Codeforces #319(Div.2) C. Vasya and Petya's Game(数学题)

本文深入探讨了游戏开发领域的关键技术,包括游戏引擎、Unity、Cocos2d-X等,以及AI音视频处理的应用,如语义识别、物体检测、语音识别等。同时,介绍了自然语言处理、区块链、隐私计算等跨领域技术如何与游戏开发相融合,为开发者提供全面的技术视角。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C. Vasya and Petya's Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 yi, he should ask the questions about.

Input

A single line contains number n (1 ≤ n ≤ 103).

Output

Print the length of the sequence of questions k (0 ≤ k ≤ n), followed by k numbers — the questions yi (1 ≤ yi ≤ n).

If there are several correct sequences of questions of the minimum length, you are allowed to print any of them.

Sample test(s)
input
4
output
3
2 4 3 
input
6
output
4
2 4 3 5 
Note

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.

题意:A给出一个数x,B每次猜一个y,A回答B,x是否可以被y整除,求出要猜的最小次数和需要猜的数。

素数筛处理出所有素数,枚举每个素数p,可以知道如果p^k<n,则p^k一定需要选,根据这个原则求出所有要猜的数。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;

const int MAXN = 1299709;
int isprime[MAXN];
int prime[MAXN];
bool vis[MAXN];

void getPrime()
{
	for (int i = 2; i*i < MAXN; i++)
	{
		if (!vis[i])
		{
			isprime[i] = 1;
			for (int j = i; j < MAXN; j = j + i)
			{
				vis[j] = true;
			}
		}
	}
	for (int i = 2; i < MAXN; i++)
	{
		if (!vis[i])
		{
			isprime[i] = 1;
		}
	}
	int ji = 0;
	for (int i = 2; i < MAXN; i++)
	{
		if (isprime[i])
		{
			prime[ji] = i;
			ji++;
		}
	}
}

int main()
{
	getPrime();
	int n;
	vector<int>ans;
	while (scanf("%d", &n) != EOF)
	{
		ans.clear();
		for (int i = 0; i <= prime[i]; i++)
		{
			int x = prime[i];
			while (x <= n)
			{
				ans.push_back(x);
				x = x*prime[i];	
			}
		}
		printf("%d\n", ans.size());
		for (int i = 0; i < ans.size(); i++)
		{
			if (i)
				printf(" ");
			printf("%d", ans[i]);
		}
		printf("\n");
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

这波lucio来全学了

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值