Skip to content

Instantly share code, notes, and snippets.

@zombrodo
Last active August 29, 2015 14:04
Show Gist options
  • Save zombrodo/5f000d9ab17cb0d3b27e to your computer and use it in GitHub Desktop.
Save zombrodo/5f000d9ab17cb0d3b27e to your computer and use it in GitHub Desktop.
Wilsons Theorem :: Stupid Integers.
// There is something not right here...
#include <stdio.h>
long f(int x);
int main(void){
int p;
printf("WILSONS THEORM for PRIME NUMBERS\nPlease enter a number: ");
scanf("%d", &p);
int ans = (f(p - 1) + 1) % p;
if(ans == 0) printf("%d IS a prime number!: ( %d - 1 )! + 1 mod ( %d == 0)\n", p, p, p);
else printf("%d is NOT a prime number!\n", p);
}
long f(int x){
int i, ret = 1;
for(i = 1; i <= x; i++) ret *= i;
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment