結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,208 KB
testcase_01 AC 71 ms
71,580 KB
testcase_02 AC 69 ms
71,400 KB
testcase_03 AC 70 ms
71,324 KB
testcase_04 AC 69 ms
71,320 KB
testcase_05 AC 69 ms
71,560 KB
testcase_06 MLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
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()


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