Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool isprime(int n)
- {
- if(n==1 || (n%2==0 && n!=2))
- {
- return false;
- }
- else if(n==2 || n==3)
- {
- return true;
- }
- else
- {
- int res=0;
- for(int i=3 ;i<=(int)sqrt(n) ;i+=2)
- {
- if(n%i==0)
- {
- res++;
- break;
- }
- }
- if(res==0)
- {
- return true;
- }
- else
- return false;
- }
- }
Add Comment
Please, Sign In to add comment