CF1566H.Xor-quiz

NOI/NOI+/CTSC

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is an interactive problem.

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

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

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

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 AA have the same answers for all cc possible queries.

这是一个交互式问题。

你将获得两个整数 cc 和 nn。评测系统持有一个随机生成的集合 AA,其中包含 nn 个互不相同的正整数,且每个元素均不超过 cc(该集合在所有满足条件的可能集合中等概率随机生成)。

你的任务是猜出集合 AA。为此,你最多可以进行 ⌈0.65⋅c⌉\lceil 0.65 \cdot c \rceil 次查询。

每次查询中,你选择一个整数 1≤x≤c1 \le x \le c。作为对该查询的响应,你将得到所有满足 y∈Ay \in A 且 gcd⁡(x,y)=1\gcd(x, y) = 1(即 xx 与 yy 互质)的 yy 的按位异或和(bitwise xor sum)。若不存在这样的 yy,则该异或和为 00。

你必须在开始时一次性提交全部查询,随后将立即收到所有查询的响应结果;此后你将无法再提出任何查询。

你需要找出任意一个集合 A′A',满足 ∣A′∣=n|A'| = n,且对全部 cc 个可能的查询(即对每个 x∈{1,2,…,c}x \in \{1,2,\dots,c\})而言,A′A' 与 AA 给出的响应完全相同。

输入格式

Firstly you are given two integers cc and nn (100≤c≤106100 \le c \le 10^6, 0≤n≤c0 \le n \le c).

首先给你两个整数 cc 和 nn(100≤c≤106100 \le c \le 10^6,0≤n≤c0 \le n \le c)。

输入输出样例

  • 输入#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,10A = {1, 4, 5, 6, 8, 10}. 77 queries are made, 7≤⌈0.65⋅10⌉=77 \le \lceil 0.65 \cdot 10 \rceil = 7, so the query limit is not exceeded.

Answers for the queries:

  • For 1010: 11 is the only number in the set AA coprime with 1010, so the answer is 11
  • For 22: 110⊕510=0012⊕1012=4101_{10} \oplus 5_{10} = 001_2 \oplus 101_2 = 4_{10}, where ⊕\oplus is the bitwise xor
  • For 33: 110⊕410⊕510⊕810⊕1010=00012⊕01002⊕01012⊕10002⊕10102=2101_{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 55: 110⊕410⊕610⊕810=00012⊕01002⊕01102⊕10002=11101_{10} \oplus 4_{10} \oplus 6_{10} \oplus 8_{10} = 0001_2 \oplus 0100_2 \oplus 0110_2 \oplus 1000_2 = 11_{10}
  • For 77: 110⊕410⊕510⊕610⊕810⊕1010=00012⊕01002⊕01012⊕01102⊕10002⊕10102=4101_{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 11: 110⊕410⊕510⊕610⊕810⊕1010=00012⊕01002⊕01012⊕01102⊕10002⊕10102=4101_{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 66: 110⊕510=00012⊕01012=4101_{10} \oplus 5_{10} = 0001_2 \oplus 0101_2 = 4_{10}

该样例仅用于帮助你理解交互协议。你的解决方案不会在该样例上进行测试。

在该样例中,A={1,4,5,6,8,10}A = \{1, 4, 5, 6, 8, 10\}。共进行了 77 次查询,而 7≤⌈0.65⋅10⌉=77 \le \lceil 0.65 \cdot 10 \rceil = 7,因此未超出查询次数限制。

各查询的答案如下:

  • 对于 1010:集合 AA 中唯一与 1010 互质的数是 11,因此答案为 11;
  • 对于 22:110⊕510=0012⊕1012=4101_{10} \oplus 5_{10} = 001_2 \oplus 101_2 = 4_{10},其中 ⊕\oplus 表示按位异或(bitwise xor);
  • 对于 33:110⊕410⊕510⊕810⊕1010=00012⊕01002⊕01012⊕10002⊕10102=2101_{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};
  • 对于 55:110⊕410⊕610⊕810=00012⊕01002⊕01102⊕10002=11101_{10} \oplus 4_{10} \oplus 6_{10} \oplus 8_{10} = 0001_2 \oplus 0100_2 \oplus 0110_2 \oplus 1000_2 = 11_{10};
  • 对于 77:110⊕410⊕510⊕610⊕810⊕1010=00012⊕01002⊕01012⊕01102⊕10002⊕10102=4101_{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};
  • 对于 11:110⊕410⊕510⊕610⊕810⊕1010=00012⊕01002⊕01012⊕01102⊕10002⊕10102=4101_{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};
  • 对于 66:110⊕510=00012⊕01012=4101_{10} \oplus 5_{10} = 0001_2 \oplus 0101_2 = 4_{10}。

输入解题思路,AI测评打分。不知道怎么写?

首页