Skip to content

Instantly share code, notes, and snippets.

@pastak
Last active December 19, 2015 15:29
Show Gist options
  • Select an option

  • Save pastak/5977005 to your computer and use it in GitHub Desktop.

Select an option

Save pastak/5977005 to your computer and use it in GitHub Desktop.
//フィボナッチ数かつ素数を小さいのから10個出力
#include <stdio.h>
int main(void){
int count = 0;
int tmp[2] = {1,1};
int n,i,j;
int is_prime;
for(i = 0;count < 10;i++){
//フィボナッチ数を求める
n = tmp[0] + tmp[1];
tmp[i%2] = n;
//素数か判定
is_prime = 1;
for(j = 2;j < n/2;j++){
//2からn/2までの数で割って1つでも割り切れなかったら素数
if(n % j == 0){
is_prime = 0;
}
}
//素数ならカウンタを進めて出力
if(is_prime){
count++;
printf("%d\n",n);
}
/*
else{
printf("(%d)\n",n);
}
*/
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment