Advertisement
a53

Puternic

a53
Apr 20th, 2021
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. ifstream fin("puternic.in");
  5. ofstream fout("puternic.out");
  6. int N, C, nrp, x, lv, ok, lp;
  7. int v[100005], p[551];
  8. bool ciur[4001];
  9. long long concat(int a, int b)
  10. {
  11. string s1 = to_string(a);
  12. string s2 = to_string(b);
  13. string s = s1 + s2;
  14. long long c = stoll(s);
  15. return c;
  16. }
  17. int puternic(long long nr)
  18. {
  19. int ex=0, k=1;
  20. while(k<=lp)
  21. {
  22. ex=0;
  23. while(nr%p[k]==0)
  24. {
  25. ex++;
  26. nr=nr/p[k];
  27. }
  28. if(ex==1)
  29. return 0;
  30. k++;
  31. }
  32. if(nr==1)
  33. return 1;
  34. if(nr<4000 && ciur[nr]==0)
  35. return 0;
  36. long long patrat=(round)(sqrt(nr));
  37. if(patrat*patrat==nr)
  38. return 1;
  39. long long cub=(round)(cbrt(nr));
  40. if(cub*cub*cub==nr)
  41. return 1;
  42. return 0;
  43.  
  44. }
  45. int main()
  46. {
  47. int j;
  48. ciur[0]=ciur[1]=1;
  49. for(int i=2; i<=4000; ++i)
  50. if(ciur[i]==0)
  51. {
  52. p[++lp]=i;
  53. j=i+i;
  54. while(j<=4000)
  55. {
  56. ciur[j]=1;
  57. j=j+i;
  58. }
  59. }
  60. fin>>C>>N;
  61. if(C==1)
  62. {
  63. for(int i=1; i<=N; ++i)
  64. {
  65. fin>>x;
  66. if(x>1)
  67. if(puternic(x))
  68. nrp++;
  69. }
  70. fout<<nrp;
  71. return 0;
  72. }
  73. for(int i=1; i<=N; ++i)
  74. {
  75. fin>>x;
  76. if(x==1)
  77. {
  78. lv++;
  79. v[lv]=1;
  80. }
  81. else if(!puternic(x))
  82. {
  83. lv++;
  84. v[lv]=x;
  85. }
  86. }
  87.  
  88. for(int i=1; i<=lv/2; ++i)
  89. {
  90. int nr1=v[i], nr2=v[lv-i+1];
  91. long long lp=concat(nr1, nr2);
  92. if(puternic(lp))
  93. {
  94. fout<<v[i]<<" "<<v[lv-i+1]<<'\n';
  95. ok=1;
  96. }
  97. }
  98. if(!ok)
  99. fout<<-1;
  100. return 0;
  101. }
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement