Mars a+b time limit:1000ms Memory limit:32768kb 64bit IO format:%i64d &%i64u Problem Description read two 25-digit Mars full Number A and B, calculate a+b. It should be noted that on Mars, the integer is not a single system, the nth bit of the system is the nth prime number. For example: 10 of the Earth's number of 2, on Mars recorded as "1,0", because the Mars single digit is 2; 10 of the Earth's number 38, on Mars, recorded as "1,1,1,0", because the Mars Single-digit is 2, 10 digits is 3, the Hundred is 5, the thousand is 7 into the system ....
Input test entry contains a number of test cases, one row for each test case, contains two Mars positive integers a and B, and the adjacent two digits of the Mars integer are separated by commas, with a space interval between a and B. When a or B enters the end of 0 o'clock, the corresponding result is not output.
Output 1 rows For each test case, that is, the a+b value of the Mars notation.
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 <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <cctype
> #include <cmath> using namespace std;
#define M int main () {int p[30],pn,n,i,b[2][30],bn[2],k;
For (pn=1,p[0]=2,n=3, pn<27; n+=2) {for (i=0; i<pn&&n%p[i]; ++i);
if (I==PN) p[pn++]=n;
} string a[2]; while (cin>>a[0]>>a[1]&& (a[0]!= "0") | |
a[1]!= "0")) {memset (b,0,sizeof (b)); For (i=0 i<2; ++i) {for (Bn[i]=0,k=a[i].size ()-1; k>=0; ++bn[i],--k) {for (b[i][bn[i]]=0,n = 1; K>=0&&a[i][k]!= ', ';
--k,n*=10) b[i][bn[i]]+=n* (a[i][k]-' 0 '); for (i=0; i<bn[0]| | i<bn[1];
++i) {if ((B[0][i]+=b[1][i]) >=p[i]) b[0][i+1]+=b[0][i]/p[i],b[0][i]%=p[i];
BOOL Fi=true;
if (b[0][i]>0) cout<<b[0][i],fi=false; for (i; i>=0;-i) {if (FI) Fi=false;
Else cout<< ",";
cout<<b[0][i];
} cout<<endl;
return 0; }