結果
| 問題 |
No.2324 Two Countries within UEC
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-28 14:21:05 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 949 bytes |
| コンパイル時間 | 268 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 39,840 KB |
| 最終ジャッジ日時 | 2024-12-27 00:39:03 |
| 合計ジャッジ時間 | 98,444 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 2 |
| other | AC * 3 WA * 7 TLE * 31 |
ソースコード
import math
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
def count_matching_towns(N, M, P, Q, queries):
results = []
for i in range(Q):
x, f = queries[i]
if f == 0:
results.append(M) # 親交度が0の場合、やきとり国の町の個数は全ての町の数Mとなる
continue
count = 0
for y in range(1, M + 1):
if gcd(x, y) == 1: # セパ国の町の番号xとやきとり国の町の番号yが互いに素であるか判定
if (x * y) % P == f:
count += 1
results.append(count)
return results
# 入力値の取得
N, M, P, Q = map(int, input().split())
queries = []
for _ in range(Q):
x, f = map(int, input().split())
queries.append((x, f))
# クエリの実行
results = count_matching_towns(N, M, P, Q, queries)
# 結果の出力
for result in results:
print(result)