Advertisement
Guest User

Na ba muie sarac nu sti info te drecu de sluga

a guest
Jan 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <fstream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. ifstream fin("vterminal.in");
  7. ofstream fout("vterminal.out");
  8.  
  9. int Prim(int n);
  10.  
  11.  
  12. int main()
  13. {
  14. int n, x;
  15. fin >> n;
  16.  
  17. int i, s = 0;
  18. bool prime = false;
  19.  
  20. for(i = 1; i <= n; i++)
  21. {
  22. fin >> x;
  23. if(Prim(x) == 1)
  24. {
  25. prime = true;
  26. x = x % 9;
  27. if(x == 0) s += 9;
  28. else s += x;
  29. }
  30. }
  31.  
  32. s = s % 9;
  33. if(!prime) fout<<0;
  34. else if(s == 0) fout << 9;
  35. else fout << s;
  36.  
  37. return 0;
  38. }
  39.  
  40. int Prim(int n)
  41. {
  42. if(n == 0 or n == 1) return 0;
  43. else
  44. {
  45. int d;
  46. for(d = 2; d <= n/2; d++)
  47. if(n % d == 0) return 0;
  48. return 1;
  49. }
  50. }
  51. //Darius o facut problema ca eu sunt ultimul sclav
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement