Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
高精乘法步进值10就能AC,但是10000就WA了,谁能解释下为什么?#include<stdio.h> #include<stdlib.h> int* mult(const int* a,const int* b) { int alen,blen,clen,lop1,lop2,rec; int* ret; rec=1; alen=a[0]; blen=b[0]; clen=alen+blen; ret = malloc(sizeof(int)*(alen+blen+1)); for(lop1=1;lop1<=clen;lop1++) ret[lop1]=0; for(lop1=1;lop1<=alen;lop1++) for(lop2=1;lop2<=blen;lop2++) ret[lop1+lop2-1]+=a[lop1]*b[lop2]; for(lop1=2;lop1<=clen;lop1++) { AC: ret[lop1]+=ret[lop1-1]/10; //WA: ret[lop1]+=ret[lop1-1]/10000; AC: ret[lop1-1]%=10; //WA: ret[lop1-1]%=10000; if(ret[lop1])rec=lop1; } ret[0]=rec; return ret; } void main() { int lop,lop1; int flag; int* n[64]; long long int tar; int b[2]={1,3}; n[0]=malloc(sizeof(int*)*2); n[0][0]=1; n[0][1]=1; for(lop=1;lop<64;lop++) n[lop] = mult( n[lop-1] , b ); do { scanf("%lld",&tar); if(!tar)break; tar--; flag=1; printf("{"); for(lop=0;lop<64;lop++) { if((tar>>lop)&1) { if(flag)flag=0; else printf(","); printf(" "); for(lop1=n[lop][0];lop1;lop1--) { printf("%d",n[lop][lop1]); } } } printf(" }\n"); }while(1); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator