Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10352    Accepted Submission(s): 3441

Problem Description

Input

Output

Sample Input
1,0 2,1
4,2,0 1,2,0
1 10,6,4,2,1
0 0

Sample Output
1,0,1
1,1,1,0
1,0,0,0,0,0

#include<stdio.h>
#include<string.h>
//将数组反转的自定义函数
int swap(int a[25], int len)
{
int i,j;
for(i=0,j=len-1; i<j; i++,j--)
{
int t=a[i];
a[i]=a[j];
a[j]=t;
}
}
int main()
{
int pn[30]={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};
int i,j,k,a[25],b[25];
char c;
while(1)
{
j=k=0;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
//巧妙处理字符串，我怎么没想到呢？
while(c!=' ')
{
scanf("%d%c",&a[j++],&c);
}
while(c!='\n')
{
scanf("%d%c",&b[k++],&c);
}
if(k==1&&j==1&&a[0]==0&&b[0]==0)
return 0;

swap(a,j);
swap(b,k);

if(j<k)
{
int t=j;
j=k;
k=t;
}
int t;
for(i=0; i<=j; i++)
{
a[i]=a[i]+b[i];
if(a[i]>=pn[i])
{
t=a[i]/pn[i];
a[i]%=pn[i];
a[i+1]+=t;
}
}
if(a[j]!=0)
for(i=j; i>=0; i--)
{
if(i!=0)
printf("%d,",a[i]);
else printf("%d\n",a[i]);
}
else
{
for(i=j-1; i>=0; i--)
{
if(i!=0)
printf("%d,",a[i]);
else printf("%d\n",a[i]);
}
}
}
return 0;
}