結果

問題 No.3179 3 time mod
ユーザー miya145592
提出日時 2025-06-13 23:04:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,246 bytes
コンパイル時間 340 ms
コンパイル使用メモリ 82,712 KB
実行使用メモリ 59,600 KB
最終ジャッジ日時 2025-06-14 01:43:48
合計ジャッジ時間 3,120 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

# https://ikatakos.com/pot/programming_algorithm/number_theory/euclidean_algorithm

# 引用(もといパクリ)
# Python で RSA 公開鍵暗号をなぞってみる - CAMPHOR- Tech Blog
# https://tech.camph.net/rsa-public-key-encryption/
 
def ex_euclid(x, y):
    c0, c1 = x, y
    a0, a1 = 1, 0
    b0, b1 = 0, 1
 
    while c1 != 0:
        m = c0 % c1
        q = c0 // c1
 
        c0, c1 = c1, m
        a0, a1 = a1, (a0 - q * a1)
        b0, b1 = b1, (b0 - q * b1)
 
    return c0, a0, b0

def exex_euclid(x,y,z):
    c, a, b = ex_euclid(x, y)
    w, m = divmod(z, c)
     
    # zがcの倍数でないなら等式は不可能
    if m != 0:
        return None
         
    u, v = x // c, y // c
    a, b = a * w, b * w
 
    # aを非負数の中で最小にする
    f, a = divmod(a, v)
    b += u * f
     
    # aを最小にしたのにbが負なら、ともに正の組は不可能
    if b < 0:
        return None
 
    return c, a, b, u, v

import sys
input = sys.stdin.readline
N = int(input())
P, Q, R = map(int, input().split())
A, B, C = map(int, input().split())
c, i, j, u, v = exex_euclid(P, -Q, B-A)
#print(c, i, j, u, v)
x = P*i+A
m = P*Q
while x%R!=C:
    x += m
#print(x)
t = P*Q*R
ans = (N-x)//t + 1
print(ans)

0