結果
| 問題 | 
                            No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
                             | 
                    
| コンテスト | |
| ユーザー | 
                             convexineq
                         | 
                    
| 提出日時 | 2021-01-23 15:51:17 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 518 ms / 2,000 ms | 
| コード長 | 452 bytes | 
| コンパイル時間 | 217 ms | 
| コンパイル使用メモリ | 82,200 KB | 
| 実行使用メモリ | 62,596 KB | 
| 最終ジャッジ日時 | 2024-12-30 23:00:03 | 
| 合計ジャッジ時間 | 4,267 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 17 | 
ソースコード
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)
            
            
            
        
            
convexineq