結果

問題 No.148 試験監督(3)
ユーザー gew1fw
提出日時 2025-06-12 20:50:13
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,225 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,156 KB
実行使用メモリ 75,904 KB
最終ジャッジ日時 2025-06-12 20:54:21
合計ジャッジ時間 4,883 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other TLE * 1 -- * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10**9 + 7

def is_greater_or_equal(a_str, b_str):
    if len(a_str) > len(b_str):
        return True
    elif len(a_str) < len(b_str):
        return False
    else:
        return a_str >= b_str

def mod_str(s, mod):
    res = 0
    for c in s:
        res = (res * 10 + int(c)) % mod
    return res

T = int(input())
for _ in range(T):
    C, P = input().split()
    
    # Check if P >= MOD
    mod_str_p = str(MOD)
    if len(P) > len(mod_str_p) or (len(P) == len(mod_str_p) and P >= mod_str_p):
        print(0)
        continue
    
    p_val = int(P)
    
    # Check if C >= P
    if not is_greater_or_equal(C, P):
        print(0)
        continue
    
    # Check if C >= 2*p_val - 1
    two_p_minus_1 = 2 * p_val - 1
    two_p_str = str(two_p_minus_1)
    if not is_greater_or_equal(C, two_p_str):
        print(0)
        continue
    
    # Calculate n_mod = (C mod MOD - p_val + 1) mod MOD
    c_mod = mod_str(C, MOD)
    n_mod = (c_mod - p_val + 1) % MOD
    if n_mod < 0:
        n_mod += MOD
    
    if n_mod < p_val:
        print(0)
    else:
        product = 1
        for i in range(p_val):
            term = (n_mod - i) % MOD
            product = (product * term) % MOD
        print(product)
0