提交时间:2021-06-23 16:40:57
运行 ID: 20943
#include <bits/stdc++.h> using namespace std; string gjd_add(string a,string b) { //加法 string c; int x=0; while(a.size()<b.size())a='0'+a; while(b.size()<a.size())b='0'+b; for(int i=a.size()-1; i>=0; i--) { int a2=a[i]-'0',b2=b[i]-'0',c2=a2+b2+x; c=(char)(c2%10+'0')+c; x=c2/10; } if(x)c=(char)(x+'0')+c; return c; } string gjd_minus(string a,string b) { //减法 string c; int x=0; while(a.size()<b.size())a='0'+a; while(b.size()<a.size())b='0'+b; for(int i=a.size()-1; i>=0; i--) { int a2=a[i]-'0',b2=b[i]-'0',c2=a2-b2-x; if(c2>=0)c=(char)(c2+'0')+c,x=0; else c=(char)((c2+10)+'0')+c,x=1; } while(c[0]=='0')c.erase(0,1); if(c.size()==0)c+='0'; return c; } string gjd_times(string a,string b) { //乘法 string c[10005],s; int as=a.size(),bs=b.size(),x; for(int i=bs-1; i>=0; i--) { x=0; for(int j=as-1; j>=0; j--) { int a2=a[j]-'0',b2=b[i]-'0',c2=a2*b2+x; c[i]=(char)(c2%10+'0')+c[i]; x=c2/10; } if(x)c[i]=(char)(x+'0')+c[i]; for(int j=1; j<bs-i; j++)c[i]+='0'; } for(int i=0; i<bs; i++)s=gjd_add(s,c[i]); while(s[0]=='0')s.erase(0,1); if(s.size()==0)s+='0'; return s; } string gjd_pow(string a,int p) { //乘方 string s="1"; for(int i=1; i<=p; i++)s=gjd_times(s,a); return s; } int main() { int k,m; scanf("%d,%d",&k,&m); string ans=gjd_minus(gjd_pow("2",m),gjd_pow("2",k-1)); if(ans.size()<6)cout<<ans<<endl; else { cout<<ans.substr(0,3)<<','<<ans.substr(ans.size()-3,3); } }