Advertisement
STANAANDREY

pb32 15/1/2020

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