提交时间:2023-10-13 13:28:01
运行 ID: 106577
#include<bits/stdc++.h> #define int long long using namespace std; int a[5005],b[5005],c[1145],ans[5005]; bool f; int cf(int a[],int b[]){ memset(c,0,sizeof(c)); int o = 0,maxl = 1050; for (int i = 0;i < maxl;i++){ for (int j = 0;j < maxl;j++){ if (i + j < maxl){ c[i + j] += a[i] * b[j]; if (c[i + j] >= 10){ c[i + j + 1] += c[i + j] / 10; c[i + j] %= 10; } } } } while (c[maxl] == 0 && maxl >= 0){ maxl--; } return maxl; } bool min_(int a[],int b[]){ int amaxl = 1140,bmaxl = 1140; while (a[amaxl] == 0 && amaxl >= 1){ amaxl--; } while (b[bmaxl] == 0 && bmaxl >= 1){ bmaxl--; } if (amaxl != bmaxl){ return amaxl < bmaxl; } for (int i = 1140;i >= 0;i--){ if (b[i] < a[i]){ return false; } else if (a[i] < b[i]){ return true; } } return false; } void fastpow(int y){ ans[0] = 1; while (y){ if (y & 1){ cf(ans,a); for (int i = 0;i < 1000;i++){ ans[i] = c[i]; } if (min_(ans,a)){ f = true; } } cf(a,a); if (min_(c,a)){ f = true; } for (int i = 0;i < 1000;i++){ a[i] = c[i]; } y >>= 1; } } signed main(){ string x; int t; cin>>x>>t; int xs = x.size(); for (int i = xs - 1;i >= 0;i--){ a[i] = x[xs - i - 1] - 48; } for (int i = xs - 1;i >= 0;i--){ b[i] = x[xs - i - 1] - 48; } fastpow(t); int maxl = 999; if (!f){ while (ans[maxl] == 0 && maxl >= 1){ maxl--; } } for (int i = maxl;i >= 0;i--){ cout<<ans[i]; } return 0; }