fork download
  1. #include <stdio.h>
  2.  
  3. int isPrime(int n) {
  4. if (n < 2) return 0;
  5. for (int i = 2; i * i <= n; i++) {
  6. if (n % i == 0) return 0;
  7. }
  8. return 1;
  9. }
  10.  
  11. int main(void) {
  12. int a[33];
  13. int count = 0;
  14.  
  15.  
  16. a[0] = 2;
  17. a[1] = -1;
  18.  
  19.  
  20. for (int i = 2; i <= 32; i++) {
  21. a[i] = -a[i - 1] + a[i - 2];
  22. }
  23.  
  24.  
  25. for (int i = 0; i <= 32; i++) {
  26. if (a[i] > 0 && isPrime(a[i])) {
  27. count++;
  28. }
  29. }
  30.  
  31.  
  32. printf("正で素数の個数は %d 個です。\n", count);
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
正で素数の個数は 5 個です。