Skip to content

Instantly share code, notes, and snippets.

@kurochan
Created July 15, 2011 10:47
Show Gist options
  • Save kurochan/1084467 to your computer and use it in GitHub Desktop.
Save kurochan/1084467 to your computer and use it in GitHub Desktop.
カーマイケル数を求める
#include<stdio.h>
#define NUM 10000
int i, j;
int car(int n){
int k = n;
if(n < 2) return 0;
for(i = 2; i < k; i++)
if(!(k % i)){
if((k / i) % i == 0) return 0;
if((n - 1) % (i - 1) != 0) return 0;
k /= i;
i = 1;
}
return k != n && (n - 1) % (k - 1) == 0;
}
int main(void){
int n;
for(n = 2; n < NUM - 1; n++)
if(car(n))
printf("%d\n", n);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment