結果

問題 No.3260 岩井スターグラフ
ユーザー しもりん
提出日時 2025-09-06 13:58:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 863 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 77,952 KB
最終ジャッジ日時 2025-09-06 13:59:29
合計ジャッジ時間 8,096 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

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 main():
    readline = sys.stdin.readline

    X, Y, N = map(int, readline().split())
    for _ in range(N):
        U, V = map(int, readline().split())
        if U == 0:
            ans = (V - 1) % Y + 1
        elif (U - 1) // Y == (V - 1) // Y:
            ans = V - U
        else:
            ans = (U - 1) % Y + (V - 1) % Y + 2
        print(ans)


if __name__ == "__main__":
    main()
0