#P8842. XOR Prime Queries

    ID: 22006 Type: Default 1000ms 256MiB

XOR Prime Queries

XOR Prime Queries

Little Ka recently became fascinated with prime numbers, and he wants to transform any number into a prime number! You are given TT queries. For each query, a number xx is provided. Your task is to count how many non-negative integers yy (with 0y<x0 \le y < x) satisfy that xyx \oplus y is a prime number, where \oplus denotes the bitwise XOR operation. A number pp is considered prime if it is greater than 1 and has no divisors other than 1 and itself.

For example, if x=5x=5, then the possible values of yy are 0, 1, 2, 3, and 4. Evaluating 5y5 \oplus y, we obtain 5, 4, 7, 6, and 1 respectively; among these, 5 and 7 are prime numbers, so the answer is 2.

inputFormat

The first line contains an integer TT, the number of queries. Each of the following TT lines contains an integer xx.

outputFormat

Output TT lines, each containing the count of non-negative integers yy (with 0y<x0 \le y < x) such that xyx \oplus y is a prime number.

sample

1
5
2

</p>