No.2323 Nafmo Does A+B
タグ : / 解いたユーザー数 292
作問者 :
hikikomori
sepa38
Problem Statement
Nafmo, a $2$nd-year undergraduate, was studying addition of base-$2$ numbers. He is trying to add the base-$2$ numbers $A$ and $B$ by column addition, computing in order from the lowest digit.
Being careless, Nafmo forgot to handle the carries at every digit and arrived at a wrong answer.
Given the base-$2$ numbers $A$ and $B$, convert the wrong answer computed by Nafmo to base $10$ and output it.
Here, ${X}_{(n)}$ denotes the base-$n$ representation of an integer $X$.
Input
$A_{(2)}$
$B_{(2)}$
- $0 \leq A_{(10)},B_{(10)} < 2^{30}$
- Both $A,B$ are base-$10$ positive integers written in base $2$
- When $A,B$ are at least $1$, the first character of each is not $0$
Output
Convert the wrong answer computed by Nafmo to base $10$ and output it.
Sample
Sample 1
Input
10 100
Output
6
For clarity, let $A=010_{(2)}$.
Computing $A+B$ in base-$2$ notation gives the following.
$A+B=010+100=110$
There are no carries in this calculation, so the answer is $6$, which is $110$ converted to base $10$.
Sample 2
Input
111 111
Output
0
Looking at the $1$s place, we have $1+1=10$. However, Nafmo made the mistake of forgetting to add the carried $1$ to the $2$s place. Thus, the calculation at the $1$s place ended up as $1+1=0$.
Since he did the same for each place, the result of the column addition is $000$, and the answer converted to base $10$ is $0$.
Sample 3
Input
10100 1011
Output
31
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。