結果

問題 No.2120 場合の数の下8桁
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-11-12 11:27:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 1,470 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 87,092 KB
実行使用メモリ 76,992 KB
最終ジャッジ日時 2023-10-12 03:38:48
合計ジャッジ時間 3,935 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,288 KB
testcase_01 AC 76 ms
71,288 KB
testcase_02 AC 76 ms
71,184 KB
testcase_03 AC 75 ms
71,336 KB
testcase_04 AC 77 ms
71,100 KB
testcase_05 AC 77 ms
71,428 KB
testcase_06 AC 76 ms
71,180 KB
testcase_07 AC 76 ms
71,316 KB
testcase_08 AC 76 ms
71,500 KB
testcase_09 AC 95 ms
76,144 KB
testcase_10 AC 160 ms
76,108 KB
testcase_11 AC 232 ms
76,132 KB
testcase_12 AC 86 ms
76,248 KB
testcase_13 AC 118 ms
76,780 KB
testcase_14 AC 126 ms
76,984 KB
testcase_15 AC 189 ms
76,832 KB
testcase_16 AC 242 ms
76,628 KB
testcase_17 AC 257 ms
76,992 KB
testcase_18 AC 76 ms
71,332 KB
testcase_19 AC 285 ms
76,812 KB
権限があれば一括ダウンロードができます

ソースコード

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()


mtwo = 2**8
mfive = 5**8
x2,y2 = 1,0
x5,y5 = 1,0

base2 = 1
num2 = 0
base5 = 1
num5 = 0

for i in range(1,m+1):
    now = i
    while now%2 == 0:
        now //= 2
        y2 += 1
    x2 = x2*now % mtwo

    now = i
    while now%5 == 0:
        now //= 5
        y5 += 1
    x5 = x5*now % mfive

    if i == m:
        base2 *= x2
        num2 += y2
        base5 *= x5
        num5 += y5

    elif i == n or i == m-n:
        _,inv2,_ = extgcd(x2,mtwo)
        _,inv5,_ = extgcd(x5,mfive)
        base2 *= inv2
        num2 -= y2
        base5 *= inv5
        num5 -= y5

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