J
janus
# include <stdio.h>
long long int factorial( long long int num){
long long int tempNum ;
long long int acc = 1;
for(tempNum = 1; tempNum < num + 1; ++tempNum){
acc = acc * tempNum;
}
return acc;
}
long long int cosAndFactorial( long long int num){
long long int factValue = factorial(num - 1);
long long int result = (factValue + (long long int)1 ) % num;
return result;
}
int main (){
long long int i;
int pcount = 0;
long long int value;
for( i = 3; i < 1000000; i = i + 2){
value = cosAndFactorial(i);
if((int)value == 0){
++pcount;
printf("Factorial : This number %llu is a Prime\n", i);
}
if(pcount == 10) {
break;
}
}
return 0;
}
I am trying to code Wilsons Theorem, http://mathworld.wolfram.com/WilsonsTheorem.html?affilliate=1
The above returns;
Factorial : This number 3 is a Prime
Factorial : This number 5 is a Prime
Factorial : This number 7 is a Prime
Factorial : This number 11 is a Prime
Factorial : This number 13 is a Prime
Factorial : This number 17 is a Prime
Factorial : This number 19 is a Prime
Factorial : This number 35 is a Prime
Regards, \Janus
long long int factorial( long long int num){
long long int tempNum ;
long long int acc = 1;
for(tempNum = 1; tempNum < num + 1; ++tempNum){
acc = acc * tempNum;
}
return acc;
}
long long int cosAndFactorial( long long int num){
long long int factValue = factorial(num - 1);
long long int result = (factValue + (long long int)1 ) % num;
return result;
}
int main (){
long long int i;
int pcount = 0;
long long int value;
for( i = 3; i < 1000000; i = i + 2){
value = cosAndFactorial(i);
if((int)value == 0){
++pcount;
printf("Factorial : This number %llu is a Prime\n", i);
}
if(pcount == 10) {
break;
}
}
return 0;
}
I am trying to code Wilsons Theorem, http://mathworld.wolfram.com/WilsonsTheorem.html?affilliate=1
The above returns;
Factorial : This number 3 is a Prime
Factorial : This number 5 is a Prime
Factorial : This number 7 is a Prime
Factorial : This number 11 is a Prime
Factorial : This number 13 is a Prime
Factorial : This number 17 is a Prime
Factorial : This number 19 is a Prime
Factorial : This number 35 is a Prime
Regards, \Janus