#include<stdio.h>
#include<string.h>
int a[150],b[150],t[150];
int pr[150];
void prime()
{
int i, j, f, cnt = 1;
pr[0] = 2;
for(i = 3; ;i++)
{
f = 1;
for(j = 2;j * j <= i; j++)
{
if(i % j == 0)
{
f = 0;
break;
}
}
if(f)
pr[cnt++] = i;
if(cnt > 120)
break;
}
}
void change(int l,int *p)
{
int cnt = 0;
for(int i = l;i >= 0;i--)
{
p[cnt++] = t[i];
}
}
int main()
{
int i, j;
prime();
while(1)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
i = 0;j = 0;
while(1)
{
scanf("%d",&t[i++]);
if(getchar() == ' ')
{
change(i - 1,a);
break;
}
}
while(1)
{
scanf("%d",&t[j++]);
if(getchar() == '\n')
{
change(j - 1,b);
break;
}
}
if(i == 1 && j == 1 && !a[0] && !b[0])
break;
int temp = 0;
for(i = 0; i < 120 ;i++ )
{
a[i] = a[i] + b[i] + temp;
temp = a[i] / pr[i];
a[i] = a[i] % pr[i];
}
for(i = 120; i >= 0;i--)
{
if(a[i] != 0)
break;
}
for(;i >= 0;i--)
{
printf("%d",a[i]);
if(i)
putchar(',');
else
putchar('\n');
}
}
return 0;
}
转载于:https://www.cnblogs.com/xindoo/archive/2013/01/12/3595123.html