結果
| 問題 |
No.3179 3 time mod
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2025-06-13 21:49:11 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 32 ms / 2,000 ms |
| コード長 | 1,028 bytes |
| コンパイル時間 | 197 ms |
| コンパイル使用メモリ | 12,160 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2025-06-14 01:40:54 |
| 合計ジャッジ時間 | 2,762 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 42 |
ソースコード
import sys
input = sys.stdin.readline
N=int(input())
P,Q,R=map(int,input().split())
A,B,C=map(int,input().split())
# 拡張ユークリッドの互除法.ax+by=gcd(a,b)となる(x,y)を一つ求め、(x,y)とgcd(x,y)を返す.
def Ext_Euc(a,b,axy=(1,0),bxy=(0,1)): # axy=a*1+b*0,bxy=a*0+b*1なので,a,bに対応する係数の初期値は(1,0),(0,1)
q,r=divmod(a,b)
if r==0:
return bxy,b # a*bxy[0]+b*bxy[1]=b
rxy=(axy[0]-bxy[0]*q,axy[1]-bxy[1]*q) # rに対応する係数を求める.
return Ext_Euc(b,r,bxy,rxy)
# 中国剰余定理(拡張ユークリッドの互除法を使う)
def Chirem(a,ma,b,mb): # N=a mod ma,N=b mod mbのときN=k mod(lcm(ma,mb))なるk,lcm(ma,mb)を返す.
(p,q),d=Ext_Euc(ma,mb)
if (a-b)%d!=0:
return -1 # 解がないとき-1を出力
return (b*ma*p+a*mb*q)//d%(ma*mb//d),ma*mb//d
ret=Chirem(A,P,B,Q)
if ret==-1:
print(0)
exit()
k,l=ret
ret=Chirem(k,l,C,R)
if ret==-1:
print(0)
exit()
x,l=ret
print((N+1-x+l-1)//l)
titia