Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("pozne.in");
- ofstream fout("pozne.out");
- bool oglPrim(int n)
- {
- int ogl = 0;
- while(n != 0)
- {
- int c = n % 10;
- ogl = ogl * 10 + c;
- n /= 10;
- }
- if(ogl < 2) return false;
- else if(ogl % 2 == 0 and ogl != 2) return false;
- else
- {
- for(int d = 3; d * d <= ogl; d += 2)
- {
- if(ogl % d == 0)
- {
- return false;
- }
- }
- }
- return true;
- }
- int main()
- {
- int p, n, s, c;
- fin >> p;
- fin >> n >> s >> c;
- if(p == 1)
- {
- for(int i = 1; i <= n; ++i)
- {
- bool gasit = false;
- int x, X;
- fin >> x;
- X = x;
- while(X != 0)
- {
- int j = X % 10;
- if(j == c) {gasit = true; break;}
- X /= 10;
- }
- if(gasit == true) fout << x << " ";
- }
- }
- else
- {
- int SUM = 0, ct = 0;
- for(int i = 1; i <= n; ++i)
- {
- int x, X, X1;
- fin >> x;
- X = X1 = x;
- if(oglPrim(X))
- {
- ++ct;
- bool gasit = false;
- while(X1 != 0)
- {
- int q = X1 % 10;
- if(q == c)
- {
- gasit = true;
- break;
- }
- X1 /= 10;
- }
- if(gasit == true) SUM += (x - s);
- else SUM += x + s;
- }
- }
- fout << ct << " ";
- if(SUM > 0) fout << 1;
- else if(SUM == 0) fout << 0;
- else if(SUM < 0) fout << -1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement