Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- long long n;
- long long powi(long long x,long long y){
- long long z=1;
- while (y--){
- z=z*x;
- if (z>10000000000) return -1;
- }
- return z;
- }
- string tostr(long long x){
- string outi="";
- while (x) outi+=char('0'+x%10),x=x/10;
- reverse(outi.begin(),outi.end());
- return outi;
- }
- string ans;
- void compare(string result){
- if (ans.length()>result.length()) ans=result;
- }
- map<long long, pair<int,int> > mp;
- map<long,long, pair<int,int> > mp2;
- int main()
- {
- cin>>n;
- ans=tostr(n);
- for (int i=2;i<=100000;i++){
- for (int j=2;j<=40;j++){
- long long x=powi(i,j);if (x==-1) continue;
- if (x==n){
- string s=tostr(i)+"^"+tostr(j);
- compare(s);
- }
- }
- }
- for (int i=2;i<=100000;i++){
- for (int j=2;j<=40;j++){
- long long x=powi(i,j);if (x==-1) continue;
- if (n%x==0){
- string s=tostr(n/x)+"*"+tostr(i)+"^"+tostr(j);
- compare(s);
- }
- }
- }
- for (int i=2;i<=100000;i++){
- for (int j=2;j<=30;j++){
- long long x=powi(i,j);
- if (x==-1) continue;
- string s="";
- if (n/x==1) s=tostr(i)+"^"+tostr(j)+"+"+tostr(n%x);
- else s=tostr(n/x)+"*"+tostr(i)+"^"+tostr(j)+"+"+tostr(n%x);
- compare(s);
- }
- }
- for (int i=2;i<=100000;i++){
- for (int j=2;j<=40;j++){
- long long x=powi(i,j);
- if (x==-1) continue;
- pair<int,int> A=mp[x];
- if (A.first!=0 && A.second!=0)
- {
- string C=tostr(A.first)+tostr(A.second);
- string B=tostr(i)+tostr(j);
- if (B.length()<C.length()) mp[x]=make_pair(i,j);
- } else
- mp[x]=make_pair(i,j);
- }
- }
- for (int i=2;i<=100000;i++){
- for (int j=2;j<=40;j++){
- long long x=powi(i,j);
- if (x==-1) continue;
- for (int k=2;k<=9;k++) {
- if (x*k>100000000000) continue;
- pair<pair<int,int> ,int> A=mp2[x*k];
- if (A.first.first!=0 && A.second!=0)
- {
- string C=tostr(A.first.first)+tostr(A.first.second)+tostr(A.second);
- string B=tostr(k)+tostr(i)+tostr(j);
- if (B.length()<C.length()) mp2[x]=make_pair(make_pair(k,i),j);
- } else
- mp2[x]=make_pair(make_pair(k,i),j);
- }
- }
- }
- for (int i=2;i<=100000;i++){
- for (int j=2;j<=40;j++){
- long long x=powi(i,j);
- if (x==-1) continue;
- if (n-x<=0) continue;
- pair<int,int> A=mp[n-x];
- if (A.first!=0 && A.first!=0)
- {
- string s=tostr(i)+"^"+tostr(j)+"+"+tostr(A.first)+"^"+tostr(A.second);
- compare(s);
- }
- pair<pair<int,int> ,int> B=mp2[n-x];
- if (B.first.first!=0 && B.second!=0)
- {
- string s=tostr(i)+"^"+tostr(j)+"+"+tostr(A.first.firsst)+"*"+tostr(A.first.second)+"^"+tostr(A.second);
- compare(s);
- }
- }
- }
- cout<<ans<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement