結果
| 問題 | No.2558 中国剰余定理 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-12-02 14:40:19 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 50 ms / 2,000 ms | 
| コード長 | 845 bytes | 
| コンパイル時間 | 290 ms | 
| コンパイル使用メモリ | 81,920 KB | 
| 実行使用メモリ | 52,736 KB | 
| 最終ジャッジ日時 | 2024-09-26 17:06:07 | 
| 合計ジャッジ時間 | 2,696 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 29 | 
ソースコード
import sys
if sys.platform =='ios':
	import clipboard
	a=clipboard.get()
	a = a.split('\n')
	text = '\n'.join(a)
	with open('input_file.txt','w') as f:
		f.write(text)
	sys.stdin = open('input_file.txt')
sys.setrecursionlimit(410000000)
stdin = sys.stdin 
def ni():return int(ns())
def na():return list(map(int, stdin.readline().split()))
def ns():return stdin.readline().strip()
def nm():return map(int,input().split())
def na_1():return list(map(lambda x:int(x)*(-1), stdin.readline().split()))
def na_2():return list(map(lambda x:int(x)-1, stdin.readline().split()))
rnage=range
rnge=range
rage = range
def mod_inv(a,m):
	m0,x0,x1 = m,0,1
	while a > 1:
		q = a//m
		m,a = a%m,m
		x0,x1 = x1-q*x0,x0
	return x1+m0 if x1 < 0 else x1
from math import *
A,B,a,b = nm()
g = gcd(A,B)
lcm = A*B//g
x = (a+A*mod_inv(A//g,B//g)*(b-a))%lcm
print(x)
            
            
            
        