Advertisement
Carbastan

Pozne

Nov 15th, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("pozne.in");
  6. ofstream fout("pozne.out");
  7.  
  8. bool oglPrim(int n)
  9. {
  10.     int ogl = 0;
  11.     while(n != 0)
  12.     {
  13.         int c = n % 10;
  14.         ogl = ogl * 10 + c;
  15.         n /= 10;
  16.     }
  17.  
  18.     if(ogl < 2) return false;
  19.     else if(ogl % 2 == 0 and ogl != 2) return false;
  20.     else
  21.     {
  22.         for(int d = 3; d * d <= ogl; d += 2)
  23.         {
  24.             if(ogl % d == 0)
  25.             {
  26.                 return false;
  27.             }
  28.         }
  29.     }
  30.     return true;
  31. }
  32.  
  33. int main()
  34. {
  35.     int p, n, s, c;
  36.     fin >> p;
  37.     fin >> n >> s >> c;
  38.  
  39.     if(p == 1)
  40.     {
  41.         for(int i = 1; i <= n; ++i)
  42.         {
  43.             bool gasit = false;
  44.             int x, X;
  45.             fin >> x;
  46.             X = x;
  47.  
  48.             while(X != 0)
  49.             {
  50.                 int j = X % 10;
  51.                 if(j == c) {gasit = true; break;}
  52.                 X /= 10;
  53.             }
  54.  
  55.             if(gasit == true) fout << x << " ";
  56.         }
  57.     }
  58.     else
  59.     {
  60.         int SUM = 0, ct = 0;
  61.  
  62.         for(int i = 1; i <= n; ++i)
  63.         {
  64.             int x, X, X1;
  65.             fin >> x;
  66.             X = X1 = x;
  67.  
  68.             if(oglPrim(X))
  69.             {
  70.                 ++ct;
  71.                 bool gasit = false;
  72.                 while(X1 != 0)
  73.                 {
  74.                     int q = X1 % 10;
  75.                     if(q == c)
  76.                     {
  77.                         gasit = true;
  78.                         break;
  79.                     }
  80.                     X1 /= 10;
  81.                 }
  82.  
  83.                 if(gasit == true) SUM += (x - s);
  84.                 else SUM += x + s;
  85.             }
  86.         }
  87.  
  88.         fout << ct << " ";
  89.  
  90.         if(SUM > 0) fout << 1;
  91.         else if(SUM == 0) fout << 0;
  92.         else if(SUM < 0) fout << -1;
  93.     }
  94.  
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement