fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int a[33];
  5. int count = 0;
  6. a[0] = 2;
  7. a[1] = -1;
  8.  
  9. for (int i = 2; i < 33; i++) {
  10. a[i] = -a[i - 1] + a[i - 2] + 2;
  11. }
  12.  
  13. for (int i = 0; i < 33; i++) {
  14. if (a[i] > 1) {
  15. int b = 1;
  16. for (int j = 2; j * j <= a[i]; j++) {
  17. if (a[i] % j == 0) {
  18. b = 0;
  19. break;
  20. }
  21. }
  22. if (b) {
  23. count++;
  24. }
  25. }
  26. }
  27. printf("この数列のa0からa32までのうち、正で素数となっている項の個数は %d 個です。\n", count);
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
この数列のa0からa32までのうち、正で素数となっている項の個数は 7 個です。