結果

問題 No.2849 Birthday Donuts
ユーザー ecotteaecottea
提出日時 2024-06-20 01:59:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,518 ms / 6,000 ms
コード長 1,203 bytes
コンパイル時間 1,595 ms
コンパイル使用メモリ 82,200 KB
実行使用メモリ 81,916 KB
最終ジャッジ日時 2024-07-01 01:48:34
合計ジャッジ時間 69,166 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
69,540 KB
testcase_01 AC 82 ms
69,108 KB
testcase_02 AC 3,493 ms
81,552 KB
testcase_03 AC 3,518 ms
81,292 KB
testcase_04 AC 3,477 ms
81,396 KB
testcase_05 AC 3,458 ms
81,656 KB
testcase_06 AC 3,504 ms
81,648 KB
testcase_07 AC 3,471 ms
81,804 KB
testcase_08 AC 3,487 ms
81,328 KB
testcase_09 AC 3,507 ms
81,328 KB
testcase_10 AC 3,497 ms
81,776 KB
testcase_11 AC 3,479 ms
81,404 KB
testcase_12 AC 3,312 ms
81,524 KB
testcase_13 AC 3,321 ms
81,332 KB
testcase_14 AC 3,318 ms
81,344 KB
testcase_15 AC 3,336 ms
81,328 KB
testcase_16 AC 3,446 ms
81,784 KB
testcase_17 AC 3,170 ms
81,280 KB
testcase_18 AC 3,427 ms
81,404 KB
testcase_19 AC 3,255 ms
81,772 KB
testcase_20 AC 3,271 ms
81,336 KB
testcase_21 AC 514 ms
81,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

n = 2 * 10**5 + 10

pf = [0] * n
for i in range(n):
    pf[i] = i

for i in range(2, n):
    if pf[i] == i:
        j = 2 * i
        while j < n:
            pf[j] = i
            j = j + i
# print(pf)

phi = [1] * n
for i in range(2, n):
    x = i
    pp = -1
    while x > 1:
        p = pf[x]
        if p == pp:
            phi[i] *= p
        else:
            phi[i] *= p - 1
        pp = p
        x //= p
# print(phi)

acc = [0] * (n + 1)
for i in range(2, n):
    acc[i] = acc[i - 1] + phi[i]


T = int(input())

prv = 0

for t in range(T):
    l, r = map(int, input().split())
    l ^= prv
    r ^= prv
    l -= 1

    res = 0
    
    sqrtR = int(math.sqrt(l + r))

    for i in range(2, sqrtR + 1):
        if l // i != r // i:
            res += phi[i]
    
    i1 = 0
    i2 = 1
    q_prv = r
    while q_prv > sqrtR:
        ql = l // (i1 + 1)
        qr = r // (i2 + 1)
        q_max = max(ql, qr)
        if i1 != i2:
            res += acc[q_prv] - acc[max(q_max, sqrtR)]
            # print(i1, i2, max(q_max, sqrtR), q_prv)
        
        q_prv = q_max
        if ql >= qr:
            i1 += 1
        else:
            i2 += 1
    
    print(res)
    
    prv = res
0