st int &b)const //大数对一个整数进行相除运算 { BigNum ret; int i,down=0; for(i=len-1;i>=0;i--) { ret.a[i]=(a[i]+down*(MAXN+1))/b; down=a[i]+down*(MAXN+1)-ret.a[i]*b; } ret.len=len; while(ret.a[ret.len-1]==0 && ret.len>1) ret.len--; return ret; } int BigNum::operator%(const int &b)const //大数对一个 int类型的变量进行取模 { int i,d=0; for(i=len-1;i>=0;i--) d=((d*(MAXN+1))%b+a[i])%b; return d; } BigNum BigNum::operator^(const int &n)const //大数的n次方运算 { BigNum t,ret(1); int i; if(n<0)exit(-1); if(n==0)return 1; if(n==1)return *this; int m=n; while(m>1) { t=*this; for(i=1;(i<<1)<=m;i<<=1) t=t*t; m-=i; ret=ret*t; if(m==1)ret=ret*(*this); } return ret; } bool BigNum::operator>(const BigNum &T)const //大数和另一个大数的大小比较 { int ln; if(len>T.len)return true; else if(len==T.len) { ln=len-1; while(a[ln]==T.a[ln]&&ln>=0) ln--; if(ln>=0 && a[ln]>T.a[ln]) return true; else return false; } else return false; } bool BigNum::operator>(const int &t)const //大数和一个int类型的变量的大小比较 { BigNum b(t); return *this>b; } void BigNum::print() //输出大数 { int i; printf("%d",a[len-1]); for(i=len-2;i>=0;i--) printf("%04d",a[i]); printf("\n"); } ll Scan() { int ch, flag = 0; ll res = 0; if((ch = getchar()) == '-') flag = 1; else if(ch >= '0' && ch <= '9') res = ch - '0'; while ((ch = getchar()) >= '0' && ch <= '9' ) res = res * 10 + ch - '0'; return flag ? -res : res; } BigNum a, b, c, d; int main() { ll t, n; t = Scan(); for (ll cas = 1; cas <= t; cas++) { a = BigNum(Scan()); b = BigNum(8); c = BigNum(7); d = BigNum(1); a = a * a * b - a * c + d; printf("Case #%lld: ", cas); a.print(); } return 0; }
|