0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

問題概要

正の整数Nが与えられる。
1, 2, 4, 8の和でNを表せ。

解法と実装

1, 2, 4, 8はそれぞれ何回使ってもいいので、全て1を使っても問題ないです。

N = int(input()) # Nを受け取る
print(N) # 個数を出力
for i in range(N):
  print(1)

1と2だけを使う場合

N = int(input())
print((N+1)//2) # 個数を出力
if N % 2 == 1: # 奇数の時は1を使う
  print(1)
for i in range(N//2):
  print(2)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?