結果

問題 No.2280 FizzBuzz Difference
ユーザー vwxyzvwxyz
提出日時 2023-09-12 05:21:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,063 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 8,476 KB
最終ジャッジ日時 2023-09-12 05:21:50
合計ジャッジ時間 1,560 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,340 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 RE -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline
import math

def Extended_Euclid(n,m):
    stack=[]
    while m:
        stack.append((n,m))
        n,m=m,n%m
    if n>=0:
        x,y=1,0
    else:
        x,y=-1,0
    for i in range(len(stack)-1,-1,-1):
        n,m=stack[i]
        x,y=y,x-(n//m)*y
    return x,y

T=int(readline())
for t in range(T):
    M,A,B,K=map(int,readline().split())
    if A<K:
        ans=0
    elif A==K:
        g=math.gcd(A,B)
        ans=M//A-1-(M//B-M//(A*B//g))
        if B%A:
            a=M-M%A
            b=M-M%b
            if b%A==0:
                b-=B
            if a<b:
                ans-=1
    else:
        X,Y=Extended_Euclid(A,B)
        g=math.gcd(A,B)
        a=A//g
        b=B//g
        ans=0
        for x,y in ((X,-Y),(-X,Y)):
            if K%g==0:
                x*=K//g
                y*=K//g
                l=max((1-x+b*A-1)//(b*A),(1-y+a*B-1)//(a*B))
                r=min((M-x*A)//(b*A),(M-y*B)//(a*B))+1
                ans+=max(r-l,0)
        #1<=(x+b*i)*A<=M
        #1<=(y+a*i)*B<=M

    print(ans)
0