結果

問題 No.176 2種類の切手
ユーザー convexineq
提出日時 2020-12-15 20:53:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 38 ms / 1,000 ms
コード長 600 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 82,416 KB
実行使用メモリ 54,044 KB
最終ジャッジ日時 2024-09-20 02:10:47
合計ジャッジ時間 2,503 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

def floor_sum(n,m,a,b):
    res = 0
    while True:
        res += ((n-1)*n*(a//m)//2) + (b//m)*n
        a %= m
        b %= m
        if a*n+b <= m:
            return res
        Y = (a*n+b)//m
        n,m,a,b = Y,a,m, a*n + b - m*Y

"""
ax + by <= t, x >= 0, y >= 0 をみたす x,y の個数
"""
def points_in_triange(a,b,t):
    return floor_sum(1+t//a,b,a,t-t//a*a) + t//a + 1

a,b,t = map(int,input().split())
r = points_in_triange(a,b,t-1)
ng = t-1
ok = 10**12
while ok-ng > 1:
    mid = (ok+ng)//2
    if r < points_in_triange(a,b,mid):
        ok = mid
    else:
        ng = mid
print(ok)
0