标签:span other hdu1230 bottom iss bsp 测试 clu 打表
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1230
题目类型:
模拟
题意概括:
第i位数的进制为第i个素数,求两个这样的数之和
解题思路:
根据给的范围,先将前29位素数打表出来,然后通过大数加法的方法即可
题目:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12890 Accepted Submission(s): 4423
# include <stdio.h> # include <string.h> int z[29]={1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103}; int main () { int t,k,i,j,m,n,o,a[500],b[500],c[500],d[500]; char x[500],y[500]; while(scanf("%s",x)) { scanf("%s",y); if(x[0]==‘0‘&&y[0]==‘0‘) return 0; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); memset(d,0,sizeof(d)); m=strlen(x); j=0; for(i=0;i<m;i++) { if(x[i]!=‘,‘) { a[j]*=10;a[j]+=x[i]-‘0‘; } else j++; } for(i=0;i<=j;i++) { c[i]=a[j-i]; } n=strlen(y); j=0; for(i=0;i<n;i++) { if(y[i]!=‘,‘) { b[j]*=10;b[j]+=y[i]-‘0‘; } else j++; } for(i=0;i<=j;i++) { d[i]=b[j-i]; } for(i=0;i<27;i++) { c[i]+=d[i]; if(c[i]>=z[i+1]) { c[i+1]++; c[i]-=z[i+1]; } } for(i=29;i>=0;i--) { if(c[i]!=0) { o=i;break; } } for(i=o;i>0;i--) printf("%d,",c[i]); printf("%d\n",c[0]); } }
标签:span other hdu1230 bottom iss bsp 测试 clu 打表
原文地址:http://www.cnblogs.com/love-sherry/p/6942398.html