fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int i,j,c,a[33];
  5. int count;
  6. a[0] = 2;a[1] = -1;
  7. count =1; //素数の個数
  8. for(i=2;i<33;i++){
  9. a[i] = -a[i-1]+a[i-2]+2; //数列の計算
  10. if(a[i]<0){ //負の数の判定
  11. continue;
  12. }
  13. c =1; //素数であると仮定
  14. for(j=2;j<a[i];j++){
  15. if(a[i]%j==0){ //素数の判定
  16. c = 0;
  17. break;
  18. }
  19. }if(c==1){ //素数の時
  20. count++;
  21. }
  22. }
  23. printf("素数の数%d個",count); //結果の表示
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0.02s 5312KB
stdin
Standard input is empty
stdout
素数の数7個