标签:lib fine bool span == 数据 cst 查看 ace
3 5 28 792
1051 81 5521
查看
这题用分治来做,另外练习操作符重载
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #include<string> #include<vector> #include<ios> #define DEBUG(x) cout<<#x<<" = "<<x<<endl using namespace std; const int MAXN=220; struct BigInt{ char digits[MAXN]; int len; BigInt(){ memset(digits,0,sizeof(digits)); len=0; }; bool isOdd() { int n=digits[0]-‘0‘; return n%2!=0; } friend istream& operator>>(istream & in,BigInt &n) { in>>n.digits; n.len=strlen(n.digits); reverse(n.digits,n.digits+n.len); return in; } friend ostream& operator<<(ostream &out, const BigInt &n) { out<<n.digits; return out; } BigInt half() { BigInt rt; int carry=0; for(int i=len-1;i>=0 ;i-- ){ int v=digits[i]-‘0‘; rt.digits[i]=(v+carry)/2+‘0‘; carry=(v+carry)%2*10; } int p=len-1; while(rt.digits[p]==‘0‘){ if(p!=0) rt.digits[p]=‘\0‘; p--; } rt.len=p+1; return rt; } }; int lastFourDigit(BigInt n) { if(n.len==1&&n.digits[0]==‘1‘)return 2011; int lf=lastFourDigit(n.half()); int t=lf*lf%10000; if(n.isOdd())return t*2011%10000; return t; } int main() { // freopen("in.txt","r",stdin); int n; cin>>n; for(int i=0;i<n ;i++ ){ BigInt bn; cin>>bn; int ans=lastFourDigit(bn); cout<<ans<<endl; } }
标签:lib fine bool span == 数据 cst 查看 ace
原文地址:https://www.cnblogs.com/MalcolmMeng/p/9304612.html