Xor Becoming Uncanny

 We define 

f(x)={f(xreverse(x))+1if x00otherwise

Here,  denotes the bitwise XOR operation and reverse is a function that takes a postive integer, reverses its binary representation (without any leading zeros) and returns the resulting number. For example reverse(2)=1reverse(6)=3reverse(7)=7

Given an integer N, find out the value of i=12N1f(i) modulo 998244353 or claim that there exists a positive integer x <2N for which f is undefined.

Input Format

  • The first line of input contains a single integer T - the number of test cases. The description of T test cases follows.
  • The first and only line of each test case contains a single integer N.

Output Format

  • For each test case output a single line containing one integer :
    • 1 if there exists a positive integer x such that x<2N and f(x) is undefined
    • i=12N1f(i) modulo 998244353 otherwise

Constraints

  • 1T3105
  • 1N109

Sample Input 1 

8
1
2
3
5
8
13
21
34

Sample Output 1 

1
4
10
58
578
20098
5236738
24641495

Explanation

Note that:

  • f(1)=f(11)+1=f(0)+1=1

  • f(2)=f(21)+1=f(3)+1=(f(33)+1)+1=(f(0)+1)+1=2

  • f(3)=f(33)+1=f(0)+1=1

  • Test case-1: i=1211f(i)=f(1)=1. So answer is 1 mod 998244353=1.

  • Test case-2: i=1221f(i)=f(1)+f(2)+f(3)=1+2+1=4. So answer is 4 mod 998244353=4.

Previous
Next Post »