Advertisement
STANAANDREY

pr2rec

Mar 4th, 2020
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int v[1000000], n;
  5.  
  6. void read(int n, int v[])
  7. {
  8.     if (n > -1)
  9.     {
  10.         read(n - 1, v);
  11.         cin >> v[n];
  12.     }
  13. }
  14.  
  15.  
  16. int isPrime(int x, int d)
  17. {
  18.     if (x == 1)
  19.         return 0;
  20.     if (d == 1)
  21.         return 1;
  22.     if (x % d == 0)
  23.         return 0;
  24.     return isPrime(x, d - 1);
  25. }
  26.  
  27. int cnt(int n, int v[])
  28. {
  29.     if (n == -1 )
  30.         return 0;
  31.     if (isPrime(v[n], v[n] / 2))
  32.         return cnt(n - 1, v) + 1;
  33.     return cnt(n - 1, v);
  34. }
  35.  
  36. int main()
  37. {
  38.     int n;
  39.     cin >> n;
  40.     read(n - 1, v);
  41.     cout << cnt(n - 1, v);
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement