Advertisement
KDOXG

super-prime

Jun 1st, 2021
978
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <tgmath.h>
  3. #include <stdbool.h>
  4. #define N 10
  5.  
  6. int main()
  7. {
  8.     printf("Mostrando os n (%d) primeiros super primos...\n", N);
  9.  
  10.     int atual = 0, testa_atual, i = 0, testa_i;
  11.     bool primo;
  12.  
  13.     for (int j = 0; j < N; j++)
  14.         while (true)
  15.         {
  16.             while (true)
  17.             {
  18.                 atual++;
  19.                 primo = true;
  20.                 if (atual <= 1)
  21.                     primo = false;
  22.                 else if (atual == 2)
  23.                     primo = true;
  24.                 else
  25.                     for (testa_atual = 2; testa_atual <= sqrt(atual); testa_atual++)
  26.                         if (atual % testa_atual == 0)
  27.                         {
  28.                             primo = false;
  29.                             break;
  30.                         }
  31.                 if (primo)
  32.                     break;
  33.             }
  34.             i++;
  35.             if (i <= 1)
  36.                 primo = false;
  37.             else if (i == 2)
  38.                 primo = true;
  39.             else
  40.                 for (testa_i = 2; testa_i <= sqrt(i); testa_i++)
  41.                     if (i % testa_i == 0)
  42.                     {
  43.                         primo = false;
  44.                         break;
  45.                     }
  46.             if (primo)
  47.             {
  48.                 printf("%d-esimo superprimo, %d-esimo primo: %d\n", j+1, i, atual);
  49.                 break;
  50.             }
  51.         }
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement