2進数

ABC238D - AND and SUM

考え方 回答例 考え方桁ごとに考えて,繰り上がりのない$(0,1), (1,0)$の桁と,繰り上がりのある$(1,1)$の桁に分ければ,次の式が成り立つ:\begin{aligned} x + y = \underbrace{(x \mathrm{\,XOR\,} y)}_{\text{繰り上がりなし}} + \underbrace{2 \times (…

ABC234C - Happy New Year!

考え方 回答例 考え方$K$を2進数表記して,1を2に置き換えたものが答え.回答例 K = int(input()) tmp = [] while K > 0: if K % 2: tmp.append('2') else: tmp.append('0') K //= 2 print(''.join(reversed(tmp))) bin(x)を使うと,整数を先頭に "0b" が付…