結果

問題 No.982 Add
ユーザー FromBooskaFromBooska
提出日時 2023-03-02 08:22:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 710 bytes
コンパイル時間 217 ms
コンパイル使用メモリ 81,772 KB
実行使用メモリ 59,828 KB
最終ジャッジ日時 2023-10-17 06:42:09
合計ジャッジ時間 2,836 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,616 KB
testcase_01 AC 38 ms
53,616 KB
testcase_02 AC 38 ms
53,616 KB
testcase_03 AC 38 ms
53,616 KB
testcase_04 AC 38 ms
53,616 KB
testcase_05 AC 44 ms
59,820 KB
testcase_06 AC 39 ms
53,616 KB
testcase_07 AC 43 ms
59,812 KB
testcase_08 AC 38 ms
53,616 KB
testcase_09 AC 48 ms
59,812 KB
testcase_10 AC 44 ms
59,828 KB
testcase_11 AC 38 ms
53,616 KB
testcase_12 AC 38 ms
53,616 KB
testcase_13 AC 38 ms
53,616 KB
testcase_14 AC 38 ms
53,616 KB
testcase_15 AC 39 ms
53,616 KB
testcase_16 AC 43 ms
59,828 KB
testcase_17 AC 43 ms
59,812 KB
testcase_18 AC 37 ms
53,616 KB
testcase_19 AC 38 ms
53,616 KB
testcase_20 AC 37 ms
53,616 KB
testcase_21 AC 38 ms
53,616 KB
testcase_22 AC 37 ms
53,616 KB
testcase_23 AC 38 ms
53,616 KB
testcase_24 AC 44 ms
59,828 KB
testcase_25 AC 44 ms
59,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 互いに素でなければ無限にあるので-1
# 互いに素な場合は、LCMまでに表せない数が何個あるかでよいか
# LCM以後表せることは実験で確認した
# 実験するとLCM未満かなり前からすべて表せそうではあるが
# LCMまでに表せる数は1次元dpで計算するか

from math import gcd
A, B = map(int, input().split())
g = gcd(A, B)
#print('g', g)
if g != 1:
    print(-1)
else:
    LCM = A*B//g
    count = [0]*(LCM+1)
    count[A] = 1
    count[B] = 1
    for i in range(LCM+1):
        if count[i] == 1:
            count[min(LCM, i+A)] = 1
            count[min(LCM, i+B)] = 1
    ans = LCM - sum(count)
    #print(LCM, count)
    print(ans)
0