結果

問題 No.982 Add
ユーザー 👑 KazunKazun
提出日時 2021-02-05 04:43:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 456 bytes
コンパイル時間 896 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 75,984 KB
最終ジャッジ日時 2023-09-14 02:56:01
合計ジャッジ時間 4,177 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
71,144 KB
testcase_01 AC 60 ms
71,316 KB
testcase_02 AC 60 ms
71,444 KB
testcase_03 AC 59 ms
71,484 KB
testcase_04 AC 61 ms
71,144 KB
testcase_05 AC 72 ms
75,820 KB
testcase_06 AC 63 ms
71,364 KB
testcase_07 AC 66 ms
75,980 KB
testcase_08 AC 64 ms
71,256 KB
testcase_09 AC 71 ms
75,624 KB
testcase_10 AC 70 ms
75,940 KB
testcase_11 AC 66 ms
71,732 KB
testcase_12 AC 68 ms
71,568 KB
testcase_13 AC 64 ms
71,364 KB
testcase_14 AC 61 ms
71,144 KB
testcase_15 AC 61 ms
71,492 KB
testcase_16 AC 66 ms
75,940 KB
testcase_17 AC 63 ms
75,832 KB
testcase_18 AC 61 ms
71,324 KB
testcase_19 AC 63 ms
71,512 KB
testcase_20 AC 64 ms
71,408 KB
testcase_21 AC 62 ms
71,396 KB
testcase_22 AC 62 ms
71,296 KB
testcase_23 AC 61 ms
71,348 KB
testcase_24 AC 68 ms
75,984 KB
testcase_25 AC 67 ms
75,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def extend_gcd(m,n):
    x0,y0,x1,y1=1,0,0,1
    while n:
        q,m,n=m//n,n,m%n
        x0,x1=x1,x0-q*x1
        y0,y1=y1,y0-q*y1
    return x0,y0,m
#================================================
from math import gcd
A,B=map(int,input().split())

if gcd(A,B)>1:
    print(-1)
else:
    X=0
    s,t,_=extend_gcd(A,B)
    N=1
    while N*(A*s+B*t)<A*B:
        p=(-N*s+B-1)//B
        q=N*t//A
        if p>q:
            X+=1
        N+=1
    print(X)
0