![見出し画像](https://assets.st-note.com/production/uploads/images/94385203/rectangle_large_type_2_6f759874ce5fc133ea19e11a280ec394.png?width=800)
atcoderアルゴリズム②
atcoderで問題を解いたので共有したいと思います。
問題①
![](https://assets.st-note.com/img/1672305000403-E4oktW5ehA.png?width=800)
![](https://assets.st-note.com/img/1672305067339-6qSKU1WYD1.png?width=800)
解答コード
N, K = map(int, input().split())
p_list = list(map(int, input().split()))
q_list = list(map(int, input().split()))
confirm = 0
flg = False
for i in p_list:
for j in q_list:
confirm = i + j
if confirm == K:
flg = True
break
if flg:
break
if flg:
print('Yes')
else:
print('No')
問題②
![](https://assets.st-note.com/img/1672305313849-9wzcbq4OfT.png)
![](https://assets.st-note.com/img/1672305366064-E1uMV7OKbx.png?width=800)
解答コード
N = int(input())
bin_lst = [] # Nを2で割った余りが格納されている。
ans = ''
# 2進数に変換
while N > 0:
bin = N % 2
N //= 2
bin_lst.append(bin)
for i in reversed(bin_lst): # reversedで格納しているlistを逆順にして正しい2進数に変換
ans += str(i)
if len(ans) <= 10: # 桁が10以上の場合は0で埋める。
print(ans.zfill(10))
else: # それ以外はそのまま表示
print(ans)
以上になります。
この記事が気に入ったらサポートをしてみませんか?