結果

問題 No.1895 Mod 2
ユーザー 👑 rin204rin204
提出日時 2022-04-08 21:39:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 481 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 77,824 KB
最終ジャッジ日時 2024-05-06 07:11:59
合計ジャッジ時間 2,155 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,352 KB
testcase_01 AC 117 ms
77,568 KB
testcase_02 AC 128 ms
77,824 KB
testcase_03 AC 114 ms
76,800 KB
testcase_04 AC 126 ms
76,672 KB
testcase_05 AC 119 ms
77,056 KB
testcase_06 AC 118 ms
77,440 KB
testcase_07 AC 119 ms
77,440 KB
testcase_08 AC 118 ms
77,184 KB
testcase_09 AC 124 ms
77,312 KB
testcase_10 AC 119 ms
76,928 KB
testcase_11 AC 123 ms
77,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""
x = 奇数の平方数 * 2^n
で表されるとき
f(x) = 1

x = 平方数 or 平方数 * 2
"""
def f(x):
    if x == 0:
        return 0
    i = int(x ** 0.5)
    i -= 2
    while (i + 1) ** 2 <= x:
        i += 1
    ret = i
    
    i = int((x // 2) ** 0.5)
    i -= 2
    while 2 * (i + 1) ** 2 <= x:
        i += 1
    return ret + i

def solve():
    l, r = map(int, input().split())
    ans = f(r) - f(l - 1)
    print(ans % 2)

for _ in range(int(input())):
    solve()
0