結果

問題 No.1968 Distance
ユーザー chineristACchineristAC
提出日時 2022-06-03 22:34:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 2,749 bytes
コンパイル時間 705 ms
コンパイル使用メモリ 81,548 KB
実行使用メモリ 64,104 KB
最終ジャッジ日時 2023-10-21 02:07:47
合計ジャッジ時間 2,859 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
56,072 KB
testcase_01 AC 48 ms
56,072 KB
testcase_02 AC 49 ms
58,120 KB
testcase_03 AC 52 ms
62,052 KB
testcase_04 AC 52 ms
62,052 KB
testcase_05 AC 55 ms
64,104 KB
testcase_06 AC 54 ms
64,104 KB
testcase_07 AC 53 ms
62,052 KB
testcase_08 AC 55 ms
64,104 KB
testcase_09 AC 53 ms
64,104 KB
testcase_10 AC 54 ms
64,104 KB
testcase_11 AC 55 ms
64,104 KB
testcase_12 AC 53 ms
62,052 KB
testcase_13 AC 53 ms
62,052 KB
testcase_14 AC 54 ms
64,104 KB
testcase_15 AC 53 ms
62,052 KB
testcase_16 AC 54 ms
64,104 KB
testcase_17 AC 54 ms
64,104 KB
testcase_18 AC 53 ms
64,104 KB
testcase_19 AC 55 ms
64,104 KB
testcase_20 AC 55 ms
64,104 KB
testcase_21 AC 54 ms
64,104 KB
testcase_22 AC 48 ms
56,072 KB
testcase_23 AC 52 ms
62,052 KB
testcase_24 AC 49 ms
56,072 KB
testcase_25 AC 50 ms
58,120 KB
testcase_26 AC 53 ms
62,052 KB
testcase_27 AC 53 ms
62,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFindVerSize():
    def __init__(self, N):
        self._parent = [n for n in range(0, N)]
        self._size = [1] * N
        self.group = N

    def find_root(self, x):
        if self._parent[x] == x: return x
        self._parent[x] = self.find_root(self._parent[x])
        stack = [x]
        while self._parent[stack[-1]]!=stack[-1]:
            stack.append(self._parent[stack[-1]])
        for v in stack:
            self._parent[v] = stack[-1]
        return self._parent[x]

    def unite(self, x, y):
        gx = self.find_root(x)
        gy = self.find_root(y)
        if gx == gy: return

        self.group -= 1

        if self._size[gx] < self._size[gy]:
            self._parent[gx] = gy
            self._size[gy] += self._size[gx]
            return gy
        else:
            self._parent[gy] = gx
            self._size[gx] += self._size[gy]
            return gx

    def get_size(self, x):
        return self._size[self.find_root(x)]

    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import log,gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

def integral(l,r,f):
    #print(l,r,f)
    res = 0
    for d in range(len(f)):
        res += f[d] * (pow(r,d+1,mod)-pow(l,d+1,mod)) * pow(d+1,mod-2,mod)
        res %= mod
    return res


mod = 998244353

N = int(input())

res = 0
for a in range(1,61):
    """
    1/2^a <= x/(1-x) <= 1/2^(a-1)
    のとき

    (1-x)をa回する(完了したら1-x)→交互
    """

    if a!=60:
        l = pow(pow(2,a,mod)+1,mod-2,mod)
        r = pow(pow(2,a-1,mod)+1,mod-2,mod)
    else:
        l = 0
        r = pow(pow(2,a-1,mod)+1,mod-2,mod)
    
    if 2**(a-1) > N:
        l = 0
        r = pow(pow(2,a-1,mod)+1,mod-2,mod)
        res += integral(l,r,[0,1])
        break

    tmp_x = 1
    tmp_1_x = 2**(a-1)
    rest = 2**(a-1)-1
    p = 1
    while True:
        if p==1:
            if N <= rest+tmp_1_x:
                q = tmp_1_x * 2 % mod
                iq = pow(q,mod-2,mod)
                res += integral(l,r,[iq,-iq])
                break
            else:
                rest += tmp_1_x
                tmp_1_x *= 2
                p = 1-p
        else:
            if N <= rest+tmp_x:
                q = tmp_x * 2 % mod
                iq = pow(q,mod-2,mod)
                res += integral(l,r,[0,iq])
                break
            else:
                rest += tmp_x
                tmp_x *= 2
                p = 1-p

        
                


res = 2 * res % mod

print(res)
0