2~36进制与2~36进制的高精度转换模板
#include <bits/stdc++.h> #define inf 2333333333333333 #define N 1000010 #define p(a) putchar(a) #define For(i,a,b) for(long long i=a;i<=b;++i) using namespace std; long long n,m; string s; void in(long long &x){ long long y=1;char c=getchar();x=0; while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();} while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();} x*=y; } void o(long long x){ if(x<0){p('-');x=-x;} if(x>9)o(x/10); p(x%10+'0'); } bool judge(string s){ For(i,0,s.size()-1) if(s[i]!='0') return 1; return 0; } string solve(string s,long long n,long long m){ string r,ans; long long d=0; if(!judge(s)) return "0"; while(judge(s)){ For(i,0,s.size()-1){ if(s[i]>='0' && s[i]<='9'){ if((d*n+s[i]-'0')/m>=10) r+=(d*n+s[i]-'0')/m-10+'A'; else r+=(d*n+s[i]-'0')/m+'0'; d=(d*n+(s[i]-'0'))%m; } else{ if((d*n+s[i]-'A'+10)/m>=10) r+=(d*n+s[i]-'A'+10)/m-10+'A'; else r+=(d*n+s[i]-'A'+10)/m+'0'; d=(d*n+(s[i]-'A'+10))%m; } } s=r; r=""; if(d>=10) ans+=d-10+'A'; else ans+=d+'0'; d=0; } reverse(ans.begin(),ans.end()); return ans; } signed main(){ while(cin>>s>>n>>m){ cout<<solve(s,n,m)<<endl; } return 0; }