1
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?

問題概要

A本お茶が入った箱を何箱変えば、B本のお茶が手に入るか。

解法と実装

if文を使って、割り切れる時はB/A、割り切れない時は+1して出力します。

A, B = map(int, input().split()) # 入力を受け取る
if B % A == 0: #割り切れる時
  print(B // A) #整数なので//
else: #割り切れない時
  print(B // A + 1)

これは、割る時にA-1を足すことで、まとめることができます。

A, B = map(int, input().split()) # 入力を受け取る
print((B+A-1)//A)
1
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
1
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?