結果
| 問題 |
No.148 試験監督(3)
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 16:25:20 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,745 bytes |
| コンパイル時間 | 256 ms |
| コンパイル使用メモリ | 81,864 KB |
| 実行使用メモリ | 75,356 KB |
| 最終ジャッジ日時 | 2025-04-16 16:26:54 |
| 合計ジャッジ時間 | 4,591 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 11 |
ソースコード
MOD = 10**9 + 7
def mod_num(s, mod):
res = 0
for c in s:
res = (res * 10 + int(c)) % mod
return res
def is_ge(c_str, two_p_minus_1_str):
len_c = len(c_str)
len_tp = len(two_p_minus_1_str)
if len_c > len_tp:
return True
if len_c < len_tp:
return False
return c_str >= two_p_minus_1_str
def compute_two_p_minus_1(p_str):
two_p = []
carry = 0
for c in reversed(p_str):
d = int(c) * 2 + carry
carry = d // 10
two_p.append(str(d % 10))
if carry > 0:
two_p.append(str(carry))
two_p = ''.join(reversed(two_p))
two_p_minus_1 = []
borrow = 1
for c in reversed(two_p):
d = int(c) - borrow
if d < 0:
d += 10
borrow = 1
else:
borrow = 0
two_p_minus_1.append(str(d))
while len(two_p_minus_1) > 0 and two_p_minus_1[-1] == '0':
two_p_minus_1.pop()
if not two_p_minus_1:
return '0'
two_p_minus_1 = ''.join(reversed(two_p_minus_1))
return two_p_minus_1
T = int(input())
for _ in range(T):
C_str, P_str = input().split()
two_p_minus_1_str = compute_two_p_minus_1(P_str)
if not is_ge(C_str, two_p_minus_1_str):
print(0)
continue
if len(P_str) > len(str(MOD)) or (len(P_str) == len(str(MOD)) and P_str >= str(MOD)):
print(0)
continue
P_val = int(P_str)
if P_val >= MOD:
print(0)
continue
C_mod = mod_num(C_str, MOD)
n_mod = (C_mod - P_val + 1) % MOD
if n_mod < 0:
n_mod += MOD
if n_mod < P_val:
print(0)
continue
ans = 1
for i in range(P_val):
ans = ans * (n_mod - i) % MOD
print(ans)
lam6er