結果

問題 No.2142 Segment Zero
ユーザー lam6er
提出日時 2025-03-31 17:32:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 810 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 82,032 KB
実行使用メモリ 59,588 KB
最終ジャッジ日時 2025-03-31 17:33:06
合計ジャッジ時間 3,305 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def main():
    import sys
    input = sys.stdin.read().split()
    N = int(input[0])
    K = int(input[1])
    S = N * (N + 1) // 2
    D = S - K
    if D == 0:
        print(0)
        return
    
    def check_single():
        max_k = int(math.isqrt(2 * D)) + 1
        for k in range(1, max_k + 1):
            if (2 * D) % k != 0:
                continue
            temp = (2 * D) // k
            numerator = temp - k + 1
            if numerator <= 0:
                continue
            if numerator % 2 != 0:
                continue
            a = numerator // 2
            b = a + k - 1
            if a >= 1 and b <= N:
                return True
        return False
    
    if check_single():
        print(1)
    else:
        print(2)

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