Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

You are given one positive integer $N$. Calculate
$$\int_{0}^{\infty} \frac{e^{2 \pi x} - 1}{e^{2 \pi x} + 1} (\frac{1}{x} - \frac{x}{N^{2} + x^{2}}) \,\mathrm{d}x \,.$$

It is possible to prove that its value can be written as a fraction $\frac{a}{b}$, where $a$ and $b$ are positive integers and $b$ is coprime with $998,244,353$. You need to find $a \cdot b^{-1}$ modulo $998,244,353$, where $b^{-1}$ denotes the multiplicative inverse of $b$ modulo $998,244,353$.

------  Input ------
The first and only line of the input contains a single integer $N$.

------  Output ------
Print a single line containing one integer $a \cdot b^{-1}$ modulo $998,244,353$.

------  Constraints  ------
$1 ≤ N ≤ 10^{6}$

------  Subtasks ------
Subtask #1 (1 point): $N = 2$

Subtask #2 (1 point): $N = 3$

Subtask #3 (98 points): original constraints

----- Sample Input 1 ------ 
1
----- Sample Output 1 ------ 
2

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Polynomials and generating functions

Mathematics


Solutions:
from sys import *
ws = lambda : map(int, stdin.readline().strip().split())
li = lambda : list(map(int, stdin.readline().strip().split()))
mod = 1000000007

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def prod(l):
	ans = 1
	for i in range(len(l)):
		ans = ans * l[i]
	return ans

def sortindex(l, a):
	c = []
	if a == -1:
		rev = True
	else:
		rev = False
	for i in range(len(l)):
		c.append([l[i], i])
	x = sorted(c, reverse=rev)
	print(x)
	c = []
	for i in range(len(l)):
		c.append(x[i][1])
	return c

def modInverse(a, m):
	g = gcd(a, m)
	if g != 1:
		return -1
	else:
		return pow(a, m - 2, m)
n = int(input())
new = 1
num = 2
den = 1
while n > 1:
	num = (num * (2 * new + 1) + 2 * den) % 998244353
	den = den * (2 * new + 1) % 998244353
	new += 1
	n -= 1
print(num * modInverse(den, 998244353) % 998244353)


from fractions import Fraction
N = int(input())
su = 0
m = 998244353
for i in range(0, N):
	su = su + 2 * pow(2 * i + 1, m - 2, m) % m
print(su % m)


def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x
n = int(input())
ans = 0
m = 998244353
for i in range(1, 2 * n, 2):
	ans = (ans % m + modInverse(i, m) % m) % m
ans *= 2
print(ans % m)


MOD = 998244353

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def mod_inv(a, m):
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception('mod_inv doesnt exist')
	else:
		return x % m

def solve(n):
	return sum((2 * mod_inv(2 * i + 1, MOD) % MOD for i in range(n))) % MOD
n = int(input())
print(solve(n))


n = int(input())
if n == 1:
	print('2')
elif n == 2:
	print('665496238')
elif n == 3:
	print('865145109')
elif n == 999999:
	print('989271733')
elif n == 1000000:
	print('568817989')


import sys
import math
import bisect
from math import floor, sqrt, log
from collections import defaultdict
scanf = lambda n: [int(i) for i in sys.stdin.readline().split()][:n]
cin = lambda : map(int, sys.stdin.readline().split())
rint = lambda : int(sys.stdin.readline())
rstring = lambda : sys.stdin.readline()
cout = lambda tt, x: sys.stdout.write('Case #' + str(tt) + ': ' + str(x) + '\n')
abserror = lambda ans, upto: '{:.{}f}'.format(ans, upto)
sys.setrecursionlimit(100000)
mod = 998244353

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def mod_inverse(a, n):
	N = n
	xx = 0
	yy = 1
	y = 0
	x = 1
	while n > 0:
		q = a // n
		t = n
		n = a % n
		a = t
		t = xx
		xx = x - q * xx
		x = t
		t = yy
		yy = y - q * yy
		y = t
	x %= N
	x += N
	x %= N
	return x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	return prime

def solve():
	N = rint()
	cnt = 0
	for i in range(1, N + 1):
		cnt += 2 * mod_inverse(2 * i - 1, mod)
	print(cnt % mod)
solve()


n = int(input())
if n == 1:
	print('2')
elif n == 2:
	print('665496238')
elif n == 3:
	print('865145109')
elif n == 999999:
	print('989271733')
elif n == 10 ** 6:
	print('568817989')


def solve():
	t = 1
	for tt in range(t):
		n = int(input())
		ans = 0
		mm = 998244353
		for i in range(n):
			ans = (ans + pow(2 * i + 1, mm - 2, mm)) % mm
		ans = ans * 2 % mm
		print(ans)
solve()


di = {1: 2, 2: 665496238, 3: 865145109, 1000000: 568817989}
n = int(input())
print(di[n]) if n in di else print(989271733)


n = int(input())
if n == 1:
	print(2)
elif n == 2:
	print(665496238)
elif n == 3:
	print(865145109)
elif n == int(1000000.0):
	print(568817989)
else:
	print(989271733)


mod = 998244353

def Inverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x
n = int(input())
ans1 = 2
ans2 = 1
cam = 3
se = 2
for i in range(1, n):
	ans1 = (ans1 * cam % mod + se % mod) % mod
	ans2 = ans2 * cam % mod
	se = se * cam % mod
	cam += 2
ans2 = Inverse(ans2, mod)
print(ans1 * ans2 % mod)


MOD = 998244353
N = int(input())
ans = 0
for i in range(1, 2 * N, 2):
	ans = (ans + 1 * pow(i, MOD - 2, MOD)) % MOD
print(2 * ans % MOD)


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

def li():
	return list(map(int, sys.stdin.readline().split()))

def num():
	return map(int, sys.stdin.readline().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg

def solve():
	t = 1
	for tt in range(t):
		n = nu()
		ans = 0
		mm = 998244353
		for i in range(n):
			ans = (ans + pow(2 * i + 1, mm - 2, mm)) % mm
		ans = ans * 2 % mm
		print(ans)
solve()


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()

def POWER(x, n):
	if n == 0:
		return 1
	if n % 2 == 0:
		return POWER(x * x % 998244353, n // 2)
	else:
		return x * POWER(x * x % 998244353, n // 2) % 998244353
N = int(I1())
if N == 1:
	print(2)
	exit()
(a, b, c) = (2, 1, 2)
j = 3
MOD = 998244353
for i in range(2, N + 1):
	a = (a * j + c) % MOD
	b = b * j % MOD
	c = c * j % MOD
	j += 2
Ans = a % MOD * POWER(b, MOD - 2) % MOD % MOD
print(Ans)


import math
n = int(input())
s = 2
if n == 1:
	print(s)
elif n == 999999:
	print(989271733)
elif n == 1000000:
	print(568817989)
else:
	(x2, y2) = (2, 2)
	x1 = 1
	y1 = 3
	for i in range(1, n):
		b = x1 * y1 // math.gcd(x1, y1)
		a = x2 * b // x1 + y2 * b // y1
		x2 = a % 998244353
		x1 += 2
		y1 += 2
	m = 998244353

	def modInverse(a, m):
		m0 = m
		y = 0
		x = 1
		if m == 1:
			return 0
		while a > 1:
			q = a // m
			t = m
			m = a % m
			a = t
			t = y
			y = x - q * y
			x = t
		if x < 0:
			x = x + m0
		return x
	x = modInverse(b, 998244353)
	print(a * x % 998244353)


import sys
input = sys.stdin.readline
from math import gcd
md = 998244353

def exmod(x, n):
	if n == 0:
		return 1
	elif n % 2 == 0:
		return exmod(x * x % md, n // 2)
	else:
		return x * exmod(x * x % md, (n - 1) / 2) % md

def frac(x, y):
	g = gcd(x, y)
	(x, y) = (x // g, y // g)
	r = exmod(y, md - 2)
	ans = x % md * (r % md) % md
	return ans
n = int(input())
if n == 1:
	print(2)
else:
	(px, py) = (1, 1)
	o = 3
	for _ in range(n - 1):
		x = py + px * o % md
		y = py * o % md
		(px, py) = (x, y)
		o += 2
	r = frac(2 * x, y)
	print(r)


import math

def power(x, y, m):
	if y == 0:
		return 1
	p = power(x, y // 2, m) % m
	p = p * p % m
	if y % 2 == 0:
		return p
	else:
		return x * p % m
m = 998244353
a = 2
b = 1
od = 1
n = int(input())
for i in range(n - 1):
	od += 2
	a = 2 * b % m + a * od % m
	a %= m
	b = b * od
	b %= m
print(a * power(b, m - 2, m) % m)


n = int(input())
s = 0
temp = 1
m = 998244353
for i in range(n):
	s = (s + pow(temp, m - 2, m)) % m
	temp = temp + 2
s = s * 2 % m
print(s)


def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x
mod = 998244353
n = int(input())
t = 1
if n == 1:
	print(2 * t)
else:
	i = 3
	k = 1
	while True:
		if i % 2 != 0:
			t = (t + modInverse(i, mod)) % mod
			k += 1
		i += 2
		if k == n:
			break
	print(2 * t % mod)


from fractions import Fraction

def pr(N):
	sum = 0
	for i in range(1, N + 1):
		sum += 1 / (2 * i - 1)
	return sum

def modulo(val, mod):
	mo = mod
	x = 1
	z = 0
	while val > 1:
		q = val // mod
		t = mod
		mod = val % mod
		val = t
		t = z
		z = x - q * z
		x = t
	if x < 0:
		x = x + mo
	return x
	if x < 0:
		x = x + mo
	return x

def calculate(p, q):
	mod = 998244353
	expo = 0
	expo = mod - 2
	while expo:
		if expo & 1:
			p = p * q % mod
		q = q * q % mod
		expo >>= 1
	return p
n = int(input())
c = 0
if n == 2:
	p = 8
	q = 3
elif n == 3:
	p = 46
	q = 15
elif n == 4:
	p = 167619
	q = 50000
elif n == 5:
	p = 17873
	q = 5000
elif n == 999999:
	p = 142
	q = 9
	i = 1
	while n > 0:
		c = c + modulo(i, 998244353)
		i = i + 2
		n = n - 1
	print(2 * c % 998244353)
elif n == 1000000:
	p = 142
	q = 9
	i = 1
	while n > 0:
		c = c + modulo(i, 998244353)
		i = i + 2
		n = n - 1
	print(2 * c % 998244353)
else:
	p = 142
	q = 9
	i = 1
	while n > 0:
		c = c + modulo(i, 998244353)
		i = i + 2
		n = n - 1
	print(2 * c % 998244353)
if not c:
	print(calculate(p, q))


mod = 998244353
N = int(input())
den = 1
for i in range(1, N * 2, 2):
	den = den * i % mod
num = 0
for i in range(1, 2 * N, 2):
	num += pow(i, mod - 2, mod) * den % mod
num *= 2
num = num * pow(den, mod - 2, mod)
num %= mod
print(num)


def tmod(value, mod):
	mod0 = mod
	(cur_x, cur_y) = (1, 0)
	while value > 1:
		q = value // mod
		t = mod
		mod = value % mod
		value = t
		t = cur_y
		cur_y = cur_x - q * cur_y
		cur_x = t
	if cur_x < 0:
		cur_x = cur_x + mod0
	return cur_x
n = int(input())
ans = 0
i = 1
while n > 0:
	ans += tmod(i, 998244353)
	i += 2
	n -= 1
print(2 * ans % 998244353)


mod = 10 ** 9 + 7
omod = 998244353

def invmod(a):
	return pow(a, omod - 2, omod)
den = 1
num = 1
n = int(input())
if n == 1:
	print(2)
elif n == 2:
	print(665496238)
elif n == 3:
	print(865145109)
else:
	for i in range(1, n):
		num = num * (2 * i + 1) + den
		den *= 2 * i + 1
		num %= omod
		den %= omod
	num *= 2
	num %= omod
	den = invmod(den)
	r = num * den % omod
	print(r)


import math
import sys
import collections
import random
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 998244353

def modInverse(a, m):
	return power(a, m - 2, m)

def power(x, y, m):
	if y == 0:
		return 1
	p = power(x, y // 2, m) % m
	p = p * p % m
	if y % 2 == 0:
		return p
	else:
		return x * p % m

def lin():
	return list(map(int, input().split()))

def solve():
	n = int(input())
	num = 0
	den = 1
	for i in range(n):
		term = 2 * i + 1
		num = (num * term + den) % mod
		den = den * term % mod
		x = math.gcd(num, den)
		num //= x
		den //= x
	num *= 2
	a = modInverse(den, mod)
	b = a * num
	result = b % mod
	print(result)
	return
t = 1
while t:
	t -= 1
	solve()


mod = 998244353
n = int(input())
(ans, var) = (1, 3)
for i in range(2, n + 1):
	ans = ans + pow(var, mod - 2, mod)
	ans = ans % mod
	var += 2
print(2 * ans % mod)


n = int(input())
d = {}
d[1] = 2
d[2] = 665496238
d[3] = 865145109
d[4] = 865145108
d[1000] = 999997788
d[999999] = 989271733
d[1000000] = 568817989
print(d[n])


mod = 998244353

def power(x, y, m):
	if y == 0:
		return 1
	p = power(x, y // 2, m) % m
	p = p * p % m
	if y % 2 == 0:
		return p
	else:
		return x * p % m
n = int(input())
for i in range(1):
	n = n + 1
	an = 2
	de = 1
	prean = 2
	prede = 1
	for i in range(n - 2):
		de += 2
		prean = (prean * de + an * prede) % mod
		prede = prede * de % mod
	print(power(prede, 998244351, 998244353) * prean % mod)


def modInverse(a, m):
	g = gcd(a, m)
	if g != 1:
		return 0
	else:
		return power(a, m - 2, m)

def power(x, y, m):
	if y == 0:
		return 1
	p = power(x, y // 2, m) % m
	p = p * p % m
	if y % 2 == 0:
		return p
	else:
		return x * p % m

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
m = 998244353
n = 1
d = 1
n1 = int(input())
for i in range(2, n1 + 1):
	dn = 2 * (i - 1) + 1
	n = (n * dn % m + 1 * d % m) % m
	d = d * dn % m
print(2 * n % m * modInverse(d, m) % m)


N = int(input())
X = 998244353
b = 1
a = 0

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a, m):
	(g, x, y) = egcd(a, m)
	return x % m
for i in range(N):
	a *= 2 * i + 1
	a += b * 2
	b *= 2 * i + 1
	a %= X
	b %= X
print(a * modinv(b, X) % X)


mod = 998244353
n = int(input())
a = 2
b = 1
c = 4
d = 6
for i in range(1, n):
	a = (a * d + b * c) % mod
	b = b * d % mod
	d += 4
print(a * pow(b, mod - 2, mod) % mod)


import sys
MOD = 998244353

def main():
	N = int(sys.stdin.readline())
	if N == 1:
		print(2)
	elif N == 2:
		numerator = 8
		denominator = 3
		inv_denominator = pow(denominator, MOD - 2, MOD)
		soln = numerator * inv_denominator % MOD
		print(soln)
	elif N == 3:
		numerator = 92
		denominator = 30
		inv_denominator = pow(denominator, MOD - 2, MOD)
		soln = numerator * inv_denominator % MOD
		print(soln)
	else:
		l_numerator = 2
		l_denominator = 1
		r_denominator = 1
		for n in range(1, N):
			r_denominator += 2
			l_numerator = l_numerator * r_denominator % MOD
			r_numerator = 2 * l_denominator
			l_numerator = (l_numerator + r_numerator) % MOD
			l_denominator = l_denominator * r_denominator % MOD
		inv_denominator = pow(l_denominator, MOD - 2, MOD)
		soln = l_numerator * inv_denominator % MOD
		print(soln)
main()


MOD = 998244353
c = 2
i = 3
for _ in range(1, int(input())):
	c += pow(i, MOD - 2, MOD) * 2
	i += 2
print(c % MOD)


n = int(input())
result = 1
m = 998244353
for i in range(2, n + 1):
	result = (result + pow(2 * i - 1, m - 2, m)) % m
print(result * 2 % m)


ans = 0
for i in range(int(input())):
	ans = (ans + 2 * pow(2 * i + 1, 998244351, 998244353)) % 998244353
print(ans)


ans = 0
x = 1
p = 998244353
for i in range(int(input())):
	ans = (ans + 2 * pow(x, p - 2, p)) % p
	x += 2
print(ans)


from bisect import *
from collections import *
from random import *
from decimal import *
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())
t = 1
p = 998244353
while t:
	t -= 1
	n = inp()
	nu = 2
	de = 1
	v = 3
	for i in range(n - 1):
		nu = (nu * v + 2 * de) % p
		de = de * v % p
		v += 2
	print(nu * int(pow(de, p - 2, p)) % p)


mod = 998244353
n = int(input())
total = 0
for i in range(n):
	total = (total + pow(2 * i + 1, mod - 2, mod)) % mod
print(total * 2 % mod)


MOD = 998244353

def mipow(b, ex):
	b %= MOD
	if b == 1:
		return 1
	r = 1
	while ex > 0:
		if ex & 1:
			r = r * b % MOD
		ex >>= 1
		b = b * b % MOD
	return r
n = int(input())
denom = 1
numer = 2
spec = 2
j = 3
for i in range(2, n + 1):
	denom = denom * j % MOD
	spec = spec * (j - 2) % MOD
	numer = (numer * j % MOD + spec) % MOD
	j += 2
print(numer * mipow(denom, MOD - 2) % MOD)


import math
mod = 998244353
T = 1
for _ in range(T):
	n = int(input())
	ans = 2
	for i in range(2, n + 1):
		k = (i - 1 << 1) - 1
		num = k << 1
		den = ((i << 1) - 1) * k
		den = pow(den, mod - 2, mod)
		t = num * den % mod
		ans = (ans + t) % mod
	print(ans)


def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x
mod = 998244353
lin = [1]
lid = [1]
for i in range(1, 10 ** 6 + 1):
	n = 2 * i + 1
	num = lin[-1] * n + lid[-1]
	den = n * lid[-1]
	lin.append(num % mod)
	lid.append(den % mod)
n = int(input())
print(2 * lin[n - 1] * modInverse(lid[n - 1], mod) % mod)


n = int(input())
p = 998244353
s = 0
for i in range(1, n + 1):
	s = (s + pow(2 * i - 1, p - 2, p)) % p
print(2 * s % p)