Advertisement
a53

gradinita

a53
Feb 26th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <fstream>
  2. #include <string>
  3. #define N 100001
  4. using namespace std;
  5. int P[N],a[N];
  6.  
  7. int sum(int n)
  8. {
  9. int nr=0;
  10. string s=to_string(n);
  11. for(unsigned int i=0;i<s.size();i+=2)
  12. nr+=s[i]-'0';
  13. return nr;
  14. }
  15.  
  16. int main()
  17. {
  18. P[0]=P[1]=1;
  19. for(int i=2;i*i<=N;++i)
  20. if(P[i]==0)
  21. for(int j=2;i*j<=N;++j)
  22. P[i*j]=1;
  23. int n,k;
  24. ifstream f("gradinita.in");
  25. f>>n>>k;
  26. int x,L=0;
  27. while(n--)
  28. {
  29. f>>x;
  30. if(P[x]&&P[sum(x)])
  31. a[++L]=x;
  32. }
  33. f.close();
  34. ofstream g("gradinita.out");
  35. if(L)
  36. {
  37. for(int i=1;i<=L;++i)
  38. if(i%k)
  39. g<<a[i]<<' ';
  40. g<<'\n';
  41. }
  42. else
  43. g<<"Toti copiii sunt obraznici!";
  44. g.close();
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement