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)