Advertisement
ioana_martin98

Untitled

May 8th, 2022
764
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. /*
  5. 8. Se citeste un numar natural n(2&lt;=n&lt;=10 3 ). Sa se afiseze pe ecran un numar natural k ce reprezinta numarul de
  6. valori prime cu n, mai mici decat n si un tablou unidimensional p ce contine cele k valori prime cu n in ordine
  7. crescatoare.
  8. Ex. n=20 =&gt; k=8, p=(1,3,7,9,11,13,17,19)
  9. */
  10. //Se citește un număr natural n, n>1. Să se determine câte perechi (a,b), 1 ≤ a ≤ b ≤ n de numere naturale sunt prime între ele
  11.  
  12. int main()
  13. {
  14.     int n, k = 0, p[1001], a, b, r, i, j;
  15.     cin >> n;
  16.     for (i = 1; i <= n; i++)
  17.     {
  18.         a = i;
  19.         b = n;
  20.         while (b != 0)
  21.         {
  22.             r = a % b;
  23.             a = b;
  24.             b = r;
  25.         }
  26.         if (a == 1)
  27.         {
  28.             k++;
  29.             p[k] = i;
  30.         }
  31.     }
  32.     for (i = 1; i <= k; i++)
  33.         cout << p[i] << " ";
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement