結果
| 問題 |
No.3253 Banned Product
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-06 02:42:10 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,298 bytes |
| コンパイル時間 | 566 ms |
| コンパイル使用メモリ | 82,452 KB |
| 実行使用メモリ | 64,460 KB |
| 最終ジャッジ日時 | 2025-09-06 02:42:12 |
| 合計ジャッジ時間 | 2,066 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 1 WA * 8 |
ソースコード
import sys
import os
IS_LOCAL = os.environ.get("LOCAL") == "true"
def debug(*args, sep=" ", end="\n", flush=False) -> None:
if IS_LOCAL:
print(*args, sep=sep, end=end, file=sys.stderr, flush=flush)
def yn(flg: bool) -> bool:
print('Yes' if flg else 'No')
return flg
def gcd(a, b):
a = abs(a); b = abs(b)
if a < b: a, b = b, a
while b > 0:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
def isqrt(N):
res = int(N**0.5) + 3
while res * res > N:
res -= 1
return res
def main():
readline = sys.stdin.readline
T = int(input())
for _ in range(T):
N, K = map(int, readline().split())
if N == K:
print(-1)
continue
if N > K * K:
print(N)
continue
m = N // K
s = isqrt(N)
seen = [False] * s
for a in range(m, s):
i = N - a * (N // a)
if i < s:
seen[i] = True
for b in range(1, s + 1):
a = min(N // b, K)
i = N - a * b
if i < s:
seen[i] = True
for i in range(s):
if not seen[i]:
print(N - i)
break
if __name__ == "__main__":
main()