結果

問題 No.2120 場合の数の下8桁
ユーザー titiatitia
提出日時 2022-11-06 04:52:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 295 ms / 2,000 ms
コード長 1,818 bytes
コンパイル時間 667 ms
コンパイル使用メモリ 86,788 KB
実行使用メモリ 76,848 KB
最終ジャッジ日時 2023-09-27 02:54:01
合計ジャッジ時間 3,457 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,572 KB
testcase_01 AC 74 ms
71,236 KB
testcase_02 AC 74 ms
71,444 KB
testcase_03 AC 76 ms
71,548 KB
testcase_04 AC 75 ms
71,164 KB
testcase_05 AC 75 ms
71,168 KB
testcase_06 AC 75 ms
71,160 KB
testcase_07 AC 75 ms
71,196 KB
testcase_08 AC 75 ms
71,420 KB
testcase_09 AC 74 ms
71,396 KB
testcase_10 AC 74 ms
71,304 KB
testcase_11 AC 75 ms
71,380 KB
testcase_12 AC 75 ms
71,444 KB
testcase_13 AC 103 ms
76,756 KB
testcase_14 AC 100 ms
76,188 KB
testcase_15 AC 175 ms
76,220 KB
testcase_16 AC 92 ms
75,972 KB
testcase_17 AC 295 ms
76,736 KB
testcase_18 AC 75 ms
71,360 KB
testcase_19 AC 265 ms
76,848 KB
権限があれば一括ダウンロードができます

ソースコード

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
ANS3=1
ANS4=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
    ANS2=ANS2*x%mod2
    ANS3=ANS3*y%mod1
    ANS4=ANS4*y%mod2

import math 
def euler_totient(x):
    ANS=x
    
    # 素因数分解
    L=int(math.sqrt(x))

    FACT=dict()

    for i in range(2,L+2):
        while x%i==0:
            FACT[i]=FACT.get(i,0)+1
            x=x//i

    if x!=1:
        FACT[x]=FACT.get(x,0)+1

    # φ(x)=x(1-1/p_1)...(1-1/p_m)という性質を使って計算

    for f in FACT:
        ANS=ANS*(f-1)//f

    return ANS

ANS1=ANS1*pow(ANS3,euler_totient(mod1)-1,mod1)%mod1
ANS2=ANS2*pow(ANS4,euler_totient(mod2)-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