luogu#P8842. [传智杯 #4 初赛] 小卡与质数 2

    ID: 7349 Type: RemoteJudge 1000ms 128MiB Tried: 0 Accepted: 0 Difficulty: 5 Uploaded By: Tags>素数判断,质数,筛法位运算传智杯

[传智杯 #4 初赛] 小卡与质数 2

Background

Xiaoka has become obsessed with prime numbers!

Problem Description

Xiaoka has recently become obsessed with prime numbers, so he wants to turn any number into a prime number!

Xiaoka has TT queries. Each time, you are given a number xx. You need to ask: how many non-negative integers yy less than xx make x⊕yx \oplus y a prime number, where ⊕\oplus denotes bitwise XOR.

Input Format

The first line contains a positive integer TT (1≤T≤105)(1 \le T \le 10^5), meaning there are TT queries.

The next TT lines each contain a positive integer xx (1≤x≤106)(1 \le x \le 10^6).

Output Format

For each query, output one line with one integer, representing the answer.

9
5
6
7
8
9
10
100
1000
10000
2
4
4
2
2
4
22
163
1132

Hint

Translated by ChatGPT 5