Mars a+b

Source: Internet
Author: User

Mars a+b

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 11713 Accepted Submission (s): 3924

First want to turn into a decimal to seek each weight value, did a half day results found that this does not

Problem description reads two Martian positive integers no more than 25 bits A and B, calculates a+b. It is important to note that on Mars, integers are not single-binary, and nth-bit is the nth prime. For example: 10 binary number 2 on Earth, on Mars as "1,0", because the number of Mars single-digit is 2 binary, the Earth's 10 number of 38, on Mars as "1,1,1,0", because the Mars single-digit is 2 binary, 10-digit is 3, the Hundred is 5 binary, thousand is 7 binary ...

The input test inputs contain several test cases, one row for each test case, two Martian positive integers a and B, a comma-separated number of adjacent two-digit numbers for the Mars Integer, and a space interval between a and B. When a or B is 0 o'clock input end, the corresponding result does not output.

Output outputs 1 rows for each test case, which is the value of the a+b of the Mars notation.

Sample input1,0 2,14,2,0 1,2,01 10,6,4,2,10 0 Sample output1,0,11,1,1,01,0,0,0,0,0
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5 using namespacestd;6 #defineLL Long Long7 intprime[ -];8 intflag=0;9 voidgetprime ()Ten { One     inti,j=0, K; A      for(i=2;; i++) -     { -flag=0; the          for(k=2; k<=sqrt (i); k++) -         { -             if(i%k==0) -             { +flag=1; -                  Break; +             } A         } at         if(!flag) -prime[j++]=i; -         if(j== -) -              Break; -     } -     return; in } - intMain () to { +     Chara[ -],b[ -]; - getprime (); the     //freopen ("In.txt", "R", stdin); *      while(SCANF ("%s%s", b)) $     {Panax Notoginseng         if(a[0]=='0'&&b[0]=='0') -              Break; the         Else +         { A             inta[ -],b[ -],c[ -]; thememset (A,0,sizeof(A)); +memset (B,0,sizeof(B)); -memset (C,0,sizeof(C)); $             intSuma=0, sumb=0, k=1, j=0, i=0, sum; $             intLena=strlen (a), lenb=strlen (b); -              for(i=lena-1; i>=0; i--) -             { thek=0; -                  while(a[i]!=',')Wuyi                 { thea[j]+= (a[i]-'0') *pow (Ten, k); -k++; Wui--; -                     if(i<0) About                          Break; $                 } -J + +; -             } -             intGa=J; Aj=0; +              for(i=lenb-1; i>=0; i--) the             { -k=0; $                  while(b[i]!=',') the                 { theb[j]+= (b[i]-'0') *pow (Ten, k); thek++; thei--; -                     if(i<0) in                          Break; the                 } theJ + +; About             } the             intgb=J; the             intC=0; the              for(i=0; i<= -; i++) +             { -c[i]= (a[i]+b[i]+c)%Prime[i]; theC= (A[I]+B[I]+C)/Prime[i];Bayi             } the              for(i= About; i>=0; i--) the                 if(c[i]!=0) -                      Break; -             intCount=i; the              for(;i>0; i--) thecout<<c[i]<<','; thecout<<C[i]; thecout<<Endl; -         } the     } the}

Mars a+b

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.