大数记录之,大数乘整型数nyoj832
想到了一个题目:对决二http://acm.nyist.net/JudgeOnline/problem.php?pid=832
但是发现有一道题目是相似的:http://acm.nyist.net/JudgeOnline/problem.php?pid=541
但是答案是不一样的、我的代码交到战斗力题目上会wa....终于找到答案了,是求大数的代码有漏洞。
求大数的代码:刚开始没有加k=0,找好久错误。
#include <stdio.h>#include <string.h>int s[100000];int cheng(int x,int p)//大数乘小数{ int i,j,k,t; int temp = 0; int c = 0;t=p; for(i=0; i<t; i++) { temp = s[i]*x+c; if(i==p-1&&temp>=10) t++; s[i] = temp%10; c = temp/10; } return t;}/*int cheng(int x,int p){ int k; int t=p; for(int i=0,k=0;i<t;i++) { s[i]=s[i]*x+k; //printf("%d\n",s[i]); if(s[i]>=10) { if(i==p-1) t++; int h=s[i]; s[i]=s[i]%10; k=h/10; } } return t;}*/int main(){int n,T;scanf("%d",&T);while(T--) { scanf("%d",&n); memset(s,0,sizeof(s)); int p=1;s[0]=1; if(n<4) { printf("%d\n",n);continue; } else { if(n%2) { p=cheng(3,p);n-=3; } while(n>0) { if(n>=6) { p=cheng(9,p); n-=6; } else if(n>=4) { p=cheng(4,p); n-=4; } else { p=cheng(2,p); n-=2; } } } for(int i=p-1;i>=0;i--) printf("%d",s[i]); printf("\n"); } return 0;}