結果

問題 No.982 Add
ユーザー ttr
提出日時 2020-02-23 23:04:57
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 621 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-10-10 22:22:18
合計ジャッジ時間 1,861 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

A,B = map(int, input().split())

def gcd(a, b):
    if a < b:
        a, b = b, a
    if a%b == 0:
        return b
    return gcd(b, a%b)

if gcd(A, B) > 1:
    ans = -1
else:
    M = 10**5
    memo = [0]*M
    ans = 0
    cnt = 0
    for i in range(1, M):
        if i%A == 0 or i%B == 0:
            memo[i] = 1
            cnt += 1
        elif i-A > 0 and memo[i-A] == 1:
            memo[i] = 1
            cnt += 1
        elif i-B > 0 and memo[i-B] == 1:
            memo[i] = 1
            cnt += 1
        else:
            ans += 1
            cnt = 0
        if cnt == min(A, B):
            break

print(ans)
0