Advertisement
Saleh127

UVA 636

Nov 11th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);
  9. cout.tie(0);
  10.  
  11. ll a,b,c,d,e,f,i,j,k,l;
  12.  
  13. while(cin>>a && a)
  14. {
  15. for(i=2; i<101; i++)
  16. {
  17. c=1;
  18. d=a;
  19. e=0;
  20. f=0;
  21. while(d)
  22. {
  23. e=e+(d%10)*c;
  24. if((d%10)>=i)
  25. {
  26. f=1;
  27. break;
  28. }
  29. c*=i;
  30. d/=10;
  31. }
  32. if(f==1)
  33. {
  34. continue;
  35. }
  36. if(ceil(sqrt(e))*ceil(sqrt(e))==e)
  37. {
  38. cout<<i<<endl;
  39. break;
  40. }
  41. }
  42.  
  43. }
  44.  
  45.  
  46. return 0;
  47. }
  48.  
  49.  
  50. /*
  51. #include <stdio.h>
  52. #include <string.h>
  53. #include <math.h>
  54.  
  55. int main() {
  56. char s[20];
  57. while(scanf("%s", s) == 1) {
  58. if(!strcmp(s, "0"))
  59. break;
  60. int len = strlen(s);
  61. int i, base = 2;
  62. for(i = 0; i < len; i++) {
  63. s[i] -= '0';
  64. if(s[i] > base)
  65. base = s[i];
  66. }
  67.  
  68. for(base++ ; ; base++) {
  69. long long a = 1, tmp = 0;
  70. for(i = len-1; i >= 0; i--)
  71. tmp += s[i]*a, a *= (long long)base;
  72. a = (long long)sqrt(tmp);
  73. if(a*a == tmp) {
  74. printf("%d\n", base);
  75. break;
  76. }
  77. }
  78. }
  79. return 0;
  80. }
  81. */
  82.  
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement