Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <cmath>
- using namespace std;
- ifstream fin("vterminal.in");
- ofstream fout("vterminal.out");
- int Prim(int n);
- int main()
- {
- int n, x;
- fin >> n;
- int i, s = 0;
- bool prime = false;
- for(i = 1; i <= n; i++)
- {
- fin >> x;
- if(Prim(x) == 1)
- {
- prime = true;
- x = x % 9;
- if(x == 0) s += 9;
- else s += x;
- }
- }
- s = s % 9;
- if(!prime) fout<<0;
- else if(s == 0) fout << 9;
- else fout << s;
- return 0;
- }
- int Prim(int n)
- {
- if(n == 0 or n == 1) return 0;
- else
- {
- int d;
- for(d = 2; d <= n/2; d++)
- if(n % d == 0) return 0;
- return 1;
- }
- }
- //Darius o facut problema ca eu sunt ultimul sclav
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement