-
November 21st, 2012, 03:10 PM
#1
prime chekcer doesnt work
hi,
A student approached me and asked why his prime checker wouldnt work. I took a look and it should work, imo, for all < 64 bit inputs.
Code:
int isitprime(unsigned long long in)
{
unsigned long long c;
unsigned long long max = sqrt(in);
if(in <= 1 )
return 0;
if(in == 2)
return 1;
for(c=2; c<max; i++)
{
if(in%c == 0)
return 0;
}
return 1;
}
checked for a bunch of primes i could think of 0,1,2,3,4,5,6,7 up to 18446744073709551557, which is supposed to be one of the largest 64 bit primes. Worked.
Does anyone see a mistake here?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|