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?

More than 3 years have passed since last update.

ABC161 C - Replacing Integer を解いた

Last updated at Posted at 2021-10-15

abc161c_1.png
abc161c_2.png
abc161c_3.png

条件にある 10^18 はさすがに for で
全部試すわけにはいかない。

abc161c.py
N,K = map(int,input().split())

num = N%K
if num == 0:
    print(0)
else:
    print(min(num,abs(num-K)))#23ms

久しぶりにやってみた。
ちょっと最適化できるようになった。

abc161c.py
N,K = map(int,input().split())
base = N%K
print(min(base,abs(base-K)))#26ms
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?