Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. long long n;
  5. long long powi(long long x,long long y){
  6. long long z=1;
  7. while (y--){
  8. z=z*x;
  9. if (z>10000000000) return -1;
  10. }
  11. return z;
  12. }
  13. string tostr(long long x){
  14. string outi="";
  15. while (x) outi+=char('0'+x%10),x=x/10;
  16. reverse(outi.begin(),outi.end());
  17. return outi;
  18. }
  19. string ans;
  20. void compare(string result){
  21. if (ans.length()>result.length()) ans=result;
  22. }
  23. map<long long, pair<int,int> > mp;
  24. map<long,long, pair<int,int> > mp2;
  25. int main()
  26. {
  27. cin>>n;
  28. ans=tostr(n);
  29. for (int i=2;i<=100000;i++){
  30. for (int j=2;j<=40;j++){
  31. long long x=powi(i,j);if (x==-1) continue;
  32. if (x==n){
  33. string s=tostr(i)+"^"+tostr(j);
  34. compare(s);
  35. }
  36. }
  37. }
  38. for (int i=2;i<=100000;i++){
  39. for (int j=2;j<=40;j++){
  40. long long x=powi(i,j);if (x==-1) continue;
  41. if (n%x==0){
  42.  
  43. string s=tostr(n/x)+"*"+tostr(i)+"^"+tostr(j);
  44. compare(s);
  45. }
  46. }
  47. }
  48. for (int i=2;i<=100000;i++){
  49. for (int j=2;j<=30;j++){
  50. long long x=powi(i,j);
  51. if (x==-1) continue;
  52. string s="";
  53. if (n/x==1) s=tostr(i)+"^"+tostr(j)+"+"+tostr(n%x);
  54. else s=tostr(n/x)+"*"+tostr(i)+"^"+tostr(j)+"+"+tostr(n%x);
  55. compare(s);
  56.  
  57. }
  58. }
  59. for (int i=2;i<=100000;i++){
  60. for (int j=2;j<=40;j++){
  61. long long x=powi(i,j);
  62. if (x==-1) continue;
  63. pair<int,int> A=mp[x];
  64. if (A.first!=0 && A.second!=0)
  65. {
  66. string C=tostr(A.first)+tostr(A.second);
  67. string B=tostr(i)+tostr(j);
  68. if (B.length()<C.length()) mp[x]=make_pair(i,j);
  69. } else
  70. mp[x]=make_pair(i,j);
  71.  
  72. }
  73. }
  74.  
  75. for (int i=2;i<=100000;i++){
  76. for (int j=2;j<=40;j++){
  77. long long x=powi(i,j);
  78. if (x==-1) continue;
  79. for (int k=2;k<=9;k++) {
  80. if (x*k>100000000000) continue;
  81. pair<pair<int,int> ,int> A=mp2[x*k];
  82. if (A.first.first!=0 && A.second!=0)
  83. {
  84. string C=tostr(A.first.first)+tostr(A.first.second)+tostr(A.second);
  85. string B=tostr(k)+tostr(i)+tostr(j);
  86. if (B.length()<C.length()) mp2[x]=make_pair(make_pair(k,i),j);
  87. } else
  88. mp2[x]=make_pair(make_pair(k,i),j);
  89. }
  90. }
  91. }
  92.  
  93. for (int i=2;i<=100000;i++){
  94. for (int j=2;j<=40;j++){
  95. long long x=powi(i,j);
  96. if (x==-1) continue;
  97. if (n-x<=0) continue;
  98. pair<int,int> A=mp[n-x];
  99.  
  100. if (A.first!=0 && A.first!=0)
  101. {
  102. string s=tostr(i)+"^"+tostr(j)+"+"+tostr(A.first)+"^"+tostr(A.second);
  103. compare(s);
  104. }
  105.  
  106. pair<pair<int,int> ,int> B=mp2[n-x];
  107. if (B.first.first!=0 && B.second!=0)
  108. {
  109. string s=tostr(i)+"^"+tostr(j)+"+"+tostr(A.first.firsst)+"*"+tostr(A.first.second)+"^"+tostr(A.second);
  110. compare(s);
  111. }
  112. }
  113. }
  114. cout<<ans<<endl;
  115. return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement