結果

問題 No.2120 場合の数の下8桁
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-11-12 11:13:15
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,576 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 86,720 KB
実行使用メモリ 842,640 KB
最終ジャッジ日時 2023-10-12 03:28:51
合計ジャッジ時間 6,036 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,348 KB
testcase_01 AC 78 ms
71,208 KB
testcase_02 AC 76 ms
71,344 KB
testcase_03 AC 75 ms
71,284 KB
testcase_04 AC 74 ms
71,352 KB
testcase_05 AC 74 ms
71,168 KB
testcase_06 AC 73 ms
71,580 KB
testcase_07 AC 74 ms
71,192 KB
testcase_08 AC 76 ms
71,472 KB
testcase_09 AC 124 ms
90,324 KB
testcase_10 MLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def extgcd(a, b):
    # ax + by = gcd(a,b)
    # return gcd(a,b), x, y
    if a == 0:
        return b, 0, 1
    else:
        g, x, y = extgcd(b % a, a)
        return g, y - (b // a) * x, x

def chineseRem(b1, m1, b2, m2):
    # x ≡ b1 (mod m1) ∧ x ≡ b2 (mod m2) <=> x ≡ r (mod m)
    # となる(r. m)を返す
    # 解無しのとき(0, -1)
    d, p, q = extgcd(m1, m2)
    if (b2 - b1) % d != 0:
        return 0, -1
    m = m1 * (m2 // d)  # m = lcm(m1, m2)
    tmp = (b2-b1) // d * p % (m2 // d)
    r = (b1 + m1 * tmp) % m
    return r, m

m = int(input())
n = int(input())

if m < n:
    print("{:08}".format(0))
    exit()
if m == n:
    print("{:08}".format(1))
    exit()

twos = [[1,0] for i in range(m+2)]
fives = [[1,0] for i in range(m+2)]

mtwo = 2**8
mfive = 5**8

for i in range(1,m+1):
    now = i
    x,y = twos[i-1]
    while now%2 == 0:
        now //= 2
        y += 1
    x = x*now % mtwo
    twos[i] = [x,y]


    now = i
    x,y = fives[i-1]
    while now%5 == 0:
        now //= 5
        y += 1
    x = x*now % mfive
    fives[i] = [x,y]
ans = 1
def nCrmodP(n,r,mod,nums):
    num = nums[n][1] - nums[r][1] - nums[n-r][1]
    base = nums[n][0]

    nn = nums[r][0]*nums[n-r][0]%mod

    _,invnn,_ = extgcd(nn,mod)
    base = base * invnn%mod
    return base,num

base2,num2 = nCrmodP(m,n,mtwo,twos)
base5,num5 = nCrmodP(m,n,mfive,fives)
if num2 >= 8:
    base2 = 0
else:
    base2 *= pow(2,num2)
if num5 >= 8:
    base5 = 0
else:
    base5 *= pow(5,num5)
ans,_ = chineseRem(base2,mtwo,base5,mfive)
ans %= 10**8
print("{:08}".format(ans))
0