結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー convexineqconvexineq
提出日時 2021-01-23 15:51:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 606 ms / 2,000 ms
コード長 452 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 76,428 KB
最終ジャッジ日時 2023-08-29 07:05:14
合計ジャッジ時間 5,495 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
76,156 KB
testcase_01 AC 76 ms
71,144 KB
testcase_02 AC 78 ms
71,640 KB
testcase_03 AC 73 ms
71,368 KB
testcase_04 AC 75 ms
71,464 KB
testcase_05 AC 75 ms
71,312 KB
testcase_06 AC 91 ms
76,244 KB
testcase_07 AC 88 ms
76,176 KB
testcase_08 AC 89 ms
76,224 KB
testcase_09 AC 89 ms
76,428 KB
testcase_10 AC 88 ms
76,304 KB
testcase_11 AC 565 ms
76,264 KB
testcase_12 AC 498 ms
76,300 KB
testcase_13 AC 606 ms
76,148 KB
testcase_14 AC 480 ms
76,384 KB
testcase_15 AC 514 ms
76,216 KB
testcase_16 AC 459 ms
76,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def extgcd(x,y):
    if y==0: return 1,0 #g=x
    r0,r1,s0,s1 = x,y,1,0
    while r1 != 0:
        r0,r1, s0,s1 = r1,r0%r1, s1,s0-r0//r1*s1
    return r0,s0,(r0-s0*x)//y

T = int(input())
for _ in range(T):
    *abc,n = map(int,input().split())
    a,b,c = sorted(abc)
    ans = 0
    g,p,q = extgcd(a,b) #ap+bq=1
    for t in range(n,-1,-c):
        if t%g==0:
            ans += t*q//a - (-t*p+b-1)//b + 1
            ans %= 1000000007
    print(ans)
0