結果

問題 No.2262 Fractions
ユーザー sotanishysotanishy
提出日時 2023-04-07 22:08:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 618 ms / 2,000 ms
コード長 1,188 bytes
コンパイル時間 384 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 116,308 KB
最終ジャッジ日時 2023-08-18 00:31:33
合計ジャッジ時間 25,937 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 414 ms
112,908 KB
testcase_01 AC 618 ms
84,012 KB
testcase_02 AC 486 ms
83,636 KB
testcase_03 AC 547 ms
82,872 KB
testcase_04 AC 515 ms
84,068 KB
testcase_05 AC 478 ms
83,428 KB
testcase_06 AC 465 ms
83,176 KB
testcase_07 AC 488 ms
83,820 KB
testcase_08 AC 470 ms
83,512 KB
testcase_09 AC 502 ms
84,332 KB
testcase_10 AC 453 ms
83,540 KB
testcase_11 AC 552 ms
83,084 KB
testcase_12 AC 553 ms
83,380 KB
testcase_13 AC 554 ms
83,812 KB
testcase_14 AC 555 ms
83,868 KB
testcase_15 AC 554 ms
83,288 KB
testcase_16 AC 341 ms
82,736 KB
testcase_17 AC 346 ms
82,648 KB
testcase_18 AC 344 ms
82,492 KB
testcase_19 AC 557 ms
113,792 KB
testcase_20 AC 533 ms
113,528 KB
testcase_21 AC 559 ms
113,584 KB
testcase_22 AC 530 ms
114,196 KB
testcase_23 AC 480 ms
109,856 KB
testcase_24 AC 547 ms
116,272 KB
testcase_25 AC 551 ms
114,592 KB
testcase_26 AC 534 ms
116,248 KB
testcase_27 AC 545 ms
116,308 KB
testcase_28 AC 541 ms
115,704 KB
testcase_29 AC 549 ms
114,492 KB
testcase_30 AC 547 ms
114,600 KB
testcase_31 AC 543 ms
114,464 KB
testcase_32 AC 541 ms
114,420 KB
testcase_33 AC 542 ms
114,260 KB
testcase_34 AC 542 ms
114,408 KB
testcase_35 AC 551 ms
114,548 KB
testcase_36 AC 554 ms
114,452 KB
testcase_37 AC 108 ms
81,160 KB
testcase_38 AC 107 ms
81,040 KB
testcase_39 AC 565 ms
114,676 KB
testcase_40 AC 564 ms
114,324 KB
testcase_41 AC 565 ms
114,332 KB
testcase_42 AC 562 ms
114,592 KB
testcase_43 AC 570 ms
114,320 KB
testcase_44 AC 559 ms
114,404 KB
testcase_45 AC 558 ms
114,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

M = 3*10**5
prime = [True] * (M+1)
totient = list(range(M+1))
for i in range(2, M+1):
    if prime[i]:
        for j in range(i, M+1, i):
            if j != i:
                prime[j] = False
            totient[j] = totient[j]//i*(i-1)


def solve(N, K):
    total = 0
    for n in range(1, N+1):
        total += totient[n]
    if K >= 2*total:
        print(-1)
        return
    flip = False
    if K > total:
        K = 2*total-K
        flip = True
    D = 10**12
    lb, ub = 0, D+1
    while ub-lb > 1:
        m = (lb+ub)//2
        cnt = 0
        g = [0]*(N+1)
        for i in range(1, N+1):
            g[i] = i*m//D
        for p in range(2, N+1):
            if not prime[p]:
                continue
            for k in range(1, N//p+1)[::-1]:
                g[k*p] -= g[k]
        if sum(g) < K:
            lb = m
        else:
            ub = m
    for d in range(1, N+1):
        if (d*lb+D-1)//D <= d*ub//D:
            n = d*ub//D
            if flip:
                d, n = n, d
            print(f"{n}/{d}")
            return


T = int(input())
for _ in range(T):
    N, K = map(int, input().split())
    solve(N, K)
0