結果

問題 No.2120 場合の数の下8桁
ユーザー titiatitia
提出日時 2022-11-06 04:38:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,305 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 87,080 KB
実行使用メモリ 81,668 KB
最終ジャッジ日時 2023-09-27 02:44:20
合計ジャッジ時間 7,730 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,224 KB
testcase_01 AC 78 ms
71,188 KB
testcase_02 AC 76 ms
71,032 KB
testcase_03 AC 77 ms
71,112 KB
testcase_04 AC 77 ms
70,964 KB
testcase_05 AC 78 ms
71,220 KB
testcase_06 AC 75 ms
71,076 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 77 ms
71,144 KB
testcase_10 AC 77 ms
71,264 KB
testcase_11 AC 76 ms
70,996 KB
testcase_12 AC 79 ms
71,140 KB
testcase_13 AC 144 ms
77,088 KB
testcase_14 AC 177 ms
77,404 KB
testcase_15 AC 1,569 ms
77,000 KB
testcase_16 AC 104 ms
76,392 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

M=int(input())
N=int(input())

if N>M:
    print(0)
    exit()

N=min(N,M-N)

TWO=0
FIVE=0

ANS1=1
ANS2=1
mod1=2**8
mod2=5**8

for i in range(N):
    x=M-i
    y=N-i

    while x%2==0:
        TWO+=1
        x//=2

    while x%5==0:
        FIVE+=1
        x//=5
     
    while y%2==0:
        TWO-=1
        y//=2

    while y%5==0:
        FIVE-=1
        y//=5

    ANS1=ANS1*x*pow(y,-1,mod1)%mod1
    ANS2=ANS2*x*pow(y,-1,mod2)%mod2

# 拡張ユークリッドの互除法.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


ANS=Chirem(ANS1,mod1,ANS2,mod2)[0]

k=ANS*(2**TWO)*(5**FIVE)
#print(ANS1,ANS2,ANS,k)

print(str(k)[-8:].zfill(8))
0