A10025 | Vasya and Petya's Game
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vasya and Petya are playing a simple game. Vasya thought of number $x$ between $1$ and $n$ , and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number $y$ ?".
The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no questions), and then Vasya responds to each question with a 'yes' or a 'no'. After receiving all the answers Petya should determine the number that Vasya thought of.
Unfortunately, Petya is not familiar with the number theory. Help him find the minimum number of questions he should ask to make a guaranteed guess of Vasya's number, and the numbers $y_{i}$ , he should ask the questions about.
Petya can ask questions like: "Is the unknown number divisible by number $y$ ?".
The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no questions), and then Vasya responds to each question with a 'yes' or a 'no'. After receiving all the answers Petya should determine the number that Vasya thought of.
Unfortunately, Petya is not familiar with the number theory. Help him find the minimum number of questions he should ask to make a guaranteed guess of Vasya's number, and the numbers $y_{i}$ , he should ask the questions about.
输入格式
A single line contains number $n$ ( $1<=n<=10^{3}$ ).
输出格式
Print the length of the sequence of questions $k$ ( $0<=k<=n$ ), followed by $k$ numbers — the questions $y_{i}$ ( $1<=y_{i}<=n$ ).
If there are several correct sequences of questions of the minimum length, you are allowed to print any of them.
If there are several correct sequences of questions of the minimum length, you are allowed to print any of them.
输入输出样例
输入 #1
4
输出 #1
3 2 4 3
输入 #2
6
输出 #2
4 2 4 3 5
The sequence from the answer to the first sample test is actually correct.
If the unknown number is not divisible by one of the sequence numbers, it is equal to $1$ .
If the unknown number is divisible by $4$ , it is $4$ .
If the unknown number is divisible by $3$ , then the unknown number is $3$ .
Otherwise, it is equal to $2$ . Therefore, the sequence of questions allows you to guess the unknown number. It can be shown that there is no correct sequence of questions of length 2 or shorter.
If the unknown number is not divisible by one of the sequence numbers, it is equal to $1$ .
If the unknown number is divisible by $4$ , it is $4$ .
If the unknown number is divisible by $3$ , then the unknown number is $3$ .
Otherwise, it is equal to $2$ . Therefore, the sequence of questions allows you to guess the unknown number. It can be shown that there is no correct sequence of questions of length 2 or shorter.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted