Advertisement
a53

bipatrat

a53
Mar 23rd, 2022
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. /**
  2. Sursa Oficiala
  3. Autor : Ncu Vlad-Laurentiu
  4. Liceul Teoretic "Mihail Kogalniceau" Vaslui
  5. **/
  6. #include<fstream>
  7. #include<math.h>
  8. using namespace std;
  9.  
  10. ifstream fin("bipatrat.in");
  11. ofstream fout("bipatrat.out");
  12.  
  13. long long x,y,p,q,i,j,aux;
  14. double rx,ry;
  15. long long n,a[200];
  16. int verif(long long n)
  17. {
  18. if(powl(floor(sqrt(n)),2)==n) return 1;
  19. else return 0;
  20. }
  21.  
  22. int main()
  23. {
  24. while(fin>>x)
  25. {
  26. n=0;
  27. if(verif(x))
  28. {
  29. p=1;
  30. while(p<=x)p=p*10;
  31. for(i=1;i<=9;i++)
  32. {
  33. y=i*p+x;
  34.  
  35. if(verif(y))
  36. {
  37. n++;
  38. a[n]=y;
  39.  
  40. }
  41. }
  42. while(p>=10)
  43. {
  44. q=p/10;
  45. for(i=0;i<=9;i++)
  46. {
  47. y=(x/q)*p+i*q+x%q;
  48. if(verif(y))
  49. {
  50. n++;
  51. a[n]=y;
  52.  
  53. }
  54. }
  55. p=q;
  56. }
  57. for(i=1;i<=n-1;i++)
  58. {
  59. for(j=i+1;j<=n;j++)
  60. {
  61. if(a[i]>a[j])
  62. {
  63. aux=a[i];
  64. a[i]=a[j];
  65. a[j]=aux;
  66. }
  67. }
  68. }
  69. }
  70. if(n>0)
  71. {
  72. fout<<a[1]<<' ';
  73. for(i=2;i<=n;i++)
  74. {
  75. if(a[i-1]<a[i])fout<<a[i]<<' ';
  76. }
  77. fout<<'\n';
  78. }
  79. else
  80. {
  81. fout<<0<<'\n';
  82. }
  83. }
  84. fout.close();
  85. fin.close();
  86. return 0;
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement