結果

問題 No.1895 Mod 2
ユーザー 👑 KazunKazun
提出日時 2022-04-08 22:02:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 341 ms / 2,000 ms
コード長 1,298 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 87,228 KB
実行使用メモリ 80,560 KB
最終ジャッジ日時 2023-08-19 00:37:46
合計ジャッジ時間 4,049 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
76,144 KB
testcase_01 AC 253 ms
80,560 KB
testcase_02 AC 329 ms
80,072 KB
testcase_03 AC 228 ms
78,640 KB
testcase_04 AC 234 ms
78,744 KB
testcase_05 AC 341 ms
78,792 KB
testcase_06 AC 330 ms
79,100 KB
testcase_07 AC 333 ms
79,452 KB
testcase_08 AC 238 ms
78,660 KB
testcase_09 AC 238 ms
79,488 KB
testcase_10 AC 181 ms
79,308 KB
testcase_11 AC 267 ms
80,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def General_Binary_Decrease_Search_Integer(L,R,cond,default=None):
    """条件式が単調減少であるとき, 整数上で二部探索を行う.
    L:解の下限
    R:解の上限
    cond:条件(1変数関数,広義単調減少 or 広義単調減少を満たす)
    default: Rで条件を満たさないときの返り値
    """

    if not(cond(L)): return default

    if cond(R): return R

    L-=1
    while R-L>1:
        C=L+(R-L)//2
        if cond(C): L=C
        else: R=C
    return L

#floor(a^(1/k)) を求める.
def Floor_Root(a,k):
    """floor(a^(1/k)) を求める.

    a:非負整数
    k:正の整数
    """
    assert 0<=a and 0<k
    if a==0: return 0
    if k==1: return a

    #大体の値を求める.
    x=int(pow(a,1/k))

    #増やす
    while pow(x+1,k)<=a:
        x+=1

    #減らす
    while pow(x,k)>a:
        x-=1
    return x
#==================================================
def g(x):
    y=1
    a=0
    while y<=x:
        check=lambda i:y*(2*i-1)**2<=x
        a+=General_Binary_Decrease_Search_Integer(1,Floor_Root(x//y,2),check,0)
        y*=2
    return a
#==================================================
T=int(input())
Ans=[0]*T
for t in range(T):
    L,R=map(int,input().split())
    Ans[t]=(g(R)-g(L-1))%2

print(*Ans,sep="\n")
0