Advertisement
Saleh127

UVA 10622

Oct 21st, 2020
78
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
  6. ll power(ll j,ll x)
  7. {
  8. ll r=j,i;
  9. for(i=2;i<=x;i++)
  10. {
  11. r*=j;
  12. }
  13. return r;
  14. }
  15.  
  16. int main()
  17. {
  18. ios_base::sync_with_stdio(0);
  19. cin.tie(0);cout.tie(0);
  20.  
  21. ll a,c,d,e,f,i,j,k,l;
  22.  
  23. while(cin>>a &&a)
  24. {
  25. l=0;
  26. if(a<0)
  27. {
  28. c=sqrt(a*-1);
  29. for(i=-2;i>=-c;i--)
  30. {
  31. d=i;
  32. e=2;
  33. while(d>a)
  34. {
  35. d=power(i,e);
  36. e++;
  37. }
  38. if(d==a)
  39. {
  40. cout<<e-1<<endl;
  41. l=1;
  42. break;
  43. }
  44. }
  45. if(!l) cout<<1<<endl;
  46. }
  47. else
  48. {
  49. c=sqrt(a);
  50. for(i=2;i<=c;i++)
  51. {
  52. d=i;
  53. e=2;
  54. while(d<a)
  55. {
  56. d=power(i,e);
  57. e++;
  58. }
  59. if(d==a)
  60. {
  61. cout<<e-1<<endl;
  62. l=1;
  63. break;
  64. }
  65. }
  66. if(!l) cout<<1<<endl;
  67. }
  68. }
  69.  
  70.  
  71. return 0;
  72. }
  73.  
Advertisement
RAW Paste Data Copied
Advertisement