#x1021. cf1566H Xor-quiz

    ID: 6151 远端评测题 4000ms 256MiB 尝试: 1 已通过: 1 难度: 10 上传者: 标签>constructive algorithmsdpinteractivemathnumber theory*3200

cf1566H Xor-quiz

Xor-quiz

题面翻译

本题是一道交互题。

交互库会随机生成一个集合 AA,满足其中每个元素都是 [1,c][1,c] 的正整数。AA 会在所有可能的情形里等概率地选取。接着令 n=An=|A|n,cn,c 是公开情报。对每个正整数 x[1,c]x\in [1,c],定义 F(A,x)F(A,x) 表示 AA 中所有和 xx 互质的数的异或和。

现在你可以提出不超过 0.65c\lceil 0.65c\rceil 个问题,每个问题的形式都必须如下:给定正整数 xx,询问 F(A,x)F(A,x) 的值。交互库在收到你的所有询问后,会一次性返回所有 F(A,x)F(A,x) 的值。

你需要构造一个大小为 nn、各元素均为 [1,c][1,c] 间正整数的集合 AA',满足对全部的 x[1,c]x\in [1,c] 都有 F(A,x)=F(A,x)F(A,x)=F(A',x)。保证一定有解。

交互格式

你需要先读入两个正整数 c,n(100c106,0nc)c,n(100\leq c\leq 10^6,0\leq n\leq c),含义如上。

接下来你需要输出一行一个整数 q(0q0.65c)q(0\leq q\leq \lceil 0.65c\rceil),表示你提出的问题数量。接下来一行输出 qq 个用空格隔开的正整数 x1,...,xq(1xic)x_1,...,x_q(1\leq x_i\leq c),表示你提出的各个问题。

在你提出所有 qq 个问题后,交互库一次性给出全部问题的答案,你可以在输入中读入它们。

最后你需要输出 nn 个用空格隔开的互不相同的正整数 A1,...,AnA'_1,...,A'_n,表示你找到的集合 AA' 中的各元素。

题目描述

This is an interactive problem.

You are given two integers c c and n n . The jury has a randomly generated set A A of distinct positive integers not greater than c c (it is generated from all such possible sets with equal probability). The size of A A is equal to n n .

Your task is to guess the set A A . In order to guess it, you can ask at most 0.65c \lceil 0.65 \cdot c \rceil queries.

In each query, you choose a single integer 1xc 1 \le x \le c . As the answer to this query you will be given the bitwise xor sum of all y y , such that yA y \in A and gcd(x,y)=1 gcd(x, y) = 1 (i.e. x x and y y are coprime). If there is no such y y this xor sum is equal to 0 0 .

You can ask all queries at the beginning and you will receive the answers to all your queries. After that, you won't have the possibility to ask queries.

You should find any set A A' , such that A=n |A'| = n and A A' and A A have the same answers for all c c possible queries.

输入格式

Firstly you are given two integers c c and n n ( 100c106 100 \le c \le 10^6 , 0nc 0 \le n \le c ).

输出格式

In the first line you should print an integer q q (0q0.65c) (0 \le q \le \lceil 0.65 \cdot c \rceil) — the number of queries you want to ask. After that in the same line print q q integers x1,x2,,xq x_1, x_2, \ldots, x_q (1xic) (1 \le x_i \le c) — the queries.

For these queries you should read q q integers, i i -th of them is the answer to the described query for x=xi x = x_i .

After that you should print n n distinct integers A1,A2,,An A'_1, A'_2, \ldots, A'_n — the set A A' you found.

If there are different sets A A' that have the same answers for all possible queries, print any of them.

If you will ask more than 0.65c \lceil 0.65 \cdot c \rceil queries or if the queries will be invalid, the interactor will terminate immediately and your program will receive verdict Wrong Answer.

After printing the queries and answers do not forget to output end of line and flush the output buffer. Otherwise, you will get the Idleness limit exceeded verdict. To do flush use:

  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • Read documentation for other languages.

Hacks

You cannot make hacks in this problem.

样例 #1

样例输入 #1

10 6

1 4 2 11 4 4 4

样例输出 #1

7 10 2 3 5 7 1 6

1 4 5 6 8 10

提示

The sample is made only for you to understand the interaction protocol. Your solution will not be tested on the sample.

In the sample A={1,4,5,6,8,10} A = \{1, 4, 5, 6, 8, 10\} . 7 7 queries are made, 70.6510=7 7 \le \lceil 0.65 \cdot 10 \rceil = 7 , so the query limit is not exceeded.

Answers for the queries:

  • For 10 10 : 1 1 is the only number in the set A A coprime with 10 10 , so the answer is 1 1
  • For 2 2 : $ 1_{10} \oplus 5_{10} = 001_2 \oplus 101_2 = 4_{10} $ , where \oplus is the bitwise xor
  • For 3 3 : $ 1_{10} \oplus 4_{10} \oplus 5_{10} \oplus 8_{10} \oplus 10_{10} = 0001_2 \oplus 0100_2 \oplus 0101_2 \oplus 1000_2 \oplus 1010_2 = 2_{10} $
  • For 5 5 : $ 1_{10} \oplus 4_{10} \oplus 6_{10} \oplus 8_{10} = 0001_2 \oplus 0100_2 \oplus 0110_2 \oplus 1000_2 = 11_{10} $
  • For 7 7 : $ 1_{10} \oplus 4_{10} \oplus 5_{10} \oplus 6_{10} \oplus 8_{10} \oplus 10_{10} = 0001_2 \oplus 0100_2 \oplus 0101_2 \oplus 0110_2 \oplus 1000_2 \oplus 1010_2 = 4_{10} $
  • For 1 1 : $ 1_{10} \oplus 4_{10} \oplus 5_{10} \oplus 6_{10} \oplus 8_{10} \oplus 10_{10} = 0001_2 \oplus 0100_2 \oplus 0101_2 \oplus 0110_2 \oplus 1000_2 \oplus 1010_2 = 4_{10} $
  • For 6 6 : $ 1_{10} \oplus 5_{10} = 0001_2 \oplus 0101_2 = 4_{10} $