結果

問題 No.2120 場合の数の下8桁
ユーザー titiatitia
提出日時 2022-11-06 04:39:51
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,302 bytes
コンパイル時間 569 ms
コンパイル使用メモリ 87,184 KB
実行使用メモリ 81,664 KB
最終ジャッジ日時 2023-09-27 02:46:04
合計ジャッジ時間 8,276 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,344 KB
testcase_01 AC 77 ms
71,232 KB
testcase_02 AC 79 ms
71,256 KB
testcase_03 AC 79 ms
71,376 KB
testcase_04 AC 76 ms
71,104 KB
testcase_05 AC 83 ms
71,212 KB
testcase_06 AC 84 ms
71,136 KB
testcase_07 AC 84 ms
71,240 KB
testcase_08 AC 84 ms
71,316 KB
testcase_09 AC 82 ms
71,036 KB
testcase_10 AC 82 ms
71,168 KB
testcase_11 AC 78 ms
71,376 KB
testcase_12 AC 79 ms
71,040 KB
testcase_13 AC 191 ms
77,172 KB
testcase_14 AC 181 ms
77,548 KB
testcase_15 AC 1,551 ms
77,516 KB
testcase_16 AC 102 ms
76,360 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

if N>M:
    print("0"*8)
    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%mod1*pow(y,-1,mod1)%mod1
    ANS2=ANS2*x%mod2*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(str(k)[-8:].zfill(8))
     
0