C. Vasya and Petya's Game

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/577/problem/C

Description

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 Input

4

Sample Output

3

2 4 3

HINT

题意

在1-n中随便选一个数,然后你可以提问,问这个数是否%y==0

问你最少问多少次,可以确定这个数

题解:

假设,你没有问p^k(p是素数,k>1),那么你是不能够分辨p^k-1 和p^k的

所以你就必须问咯

所以最后答案只需要把小于等于n的素数以及素数的幂都输出出来就好了

代码:

//qscqesze
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 500001
#define mod 1001
#define eps 1e-9
#define pi 3.1415926
int Num;
//const int inf=0x7fffffff;
const ll inf=;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//*************************************************************************************
vector<int> ans;
vector<int> Q;
int main()
{
int n=read();
if(n==)
{
printf("");
return ;
}
for(int i=;i<=n;i++)
{
int flag = ;
for(int j=;j*j<=i;j++)
{
if(i%j)continue;
flag=;break;
}
if(!flag)ans.push_back(i);
}
for(int i=;i<ans.size();i++)
{
int j = ans[i];
for(;j<=n;j*=ans[i])
Q.push_back(j);
}
printf("%d\n",Q.size());
for(int i=;i<Q.size();i++)
printf("%d ",Q[i]);
printf("\n");
}

Codeforces Codeforces Round #319 (Div. 2) C. Vasya and Petya's Game 数学的更多相关文章

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

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

  2. 数学 - Codeforces Round #319 (Div. 1)A. Vasya and Petya's Game

    Vasya and Petya's Game Problem's Link Mean: 给定一个n,系统随机选定了一个数x,(1<=x<=n). 你可以询问系统x是否能被y整除,系统会回答 ...

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

                                                     C. Vasya and Petya's Game                           ...

  4. Codeforces Round #319 (Div. 2) C Vasya and Petya's Game (数论)

    因为所有整数都能被唯一分解,p1^a1*p2^a2*...*pi^ai,而一次询问的数可以分解为p1^a1k*p2^a2k*...*pi^aik,这次询问会把所有a1>=a1k &&am ...

  5. Codeforces Beta Round #85 (Div. 1 Only) C (状态压缩或是数学?)

    C. Petya and Spiders Little Petya loves training spiders. Petya has a board n × m in size. Each cell ...

  6. 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root

    题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...

  7. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  8. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  9. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

随机推荐

  1. POJ1182

    这题需要注意就是 并查集中 相对位置 注意与绝对距离区别 #include<cstdio> #define maxn 50005 int ans,i,a,b,p,fa,fb,n,k; in ...

  2. bzoj3294

    感觉自己就是不怎么擅长计数的问题 设f[k,i,j]表示前k种颜色占据了i行j列的方案 g[k,i,j]表示第k种颜色占据了i行j列的方案,注意要减去并没占据满i行j列的情况 然后转移就很好写了 像这 ...

  3. [POJ 1365] Prime Land

    Prime Land Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3211   Accepted: 1473 Descri ...

  4. Vs 引用第三方DLL文件 版本不一致问题 (npoi与memcached中的ICSharpCode.SharpZipLib版本冲突的解决方案)

    最近在 做 MailChimp 与网站功能 集成时,发现 MailChimp 2API 中的 MailChimp.dll  中的依赖项 SerivceStack.Text.dll (版本为3.9.71 ...

  5. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.3.6

    If $A$ is a contraction, show that $$\bex A^*(I-AA^*)^{1/2}=(I-A^*A)^{1/2}A^*. \eex$$ Use this to sh ...

  6. 方格取数(1)(HDU 1565状压dp)

    题意: 给你一个n*n的格子的棋盘,每个格子里面有一个非负数. 从中取出若干个数,使得任意的两个数所在的格子没有公共边,就是说所取的数所在的2个格子不能相邻,并且取出的数的和最大.   分析:直接枚举 ...

  7. 烧写u_boot系统和linux系统

    今天下午准备烧写一下u_boot还有linux系统,因为是笔记本电脑,吐槽一下,笔记本电脑的usb转串口不是怎么稳定,dnw下对应的驱动也不怎么好用,导致在笔记本电脑上烧写系统的成功率比较低,本来三点 ...

  8. 交易策略研究 R库

    本文在Creative Commons许可证下发布 交易策略研究 R库,直接安装:xts, TTR,quantmod,RTAQ,PerformanceAnalytics,FactorAnalytics ...

  9. [GRYZ2015]快排练习

    用快排完成n(n<=100)个人年龄的从小到大的排序,要求出生年相同的按月排. 输入:第一行n个人 2到n+1行出生  年  月(1992 9) 输出:年龄的从小到大的排序. type ss=r ...

  10. Makefile.am讲解

    Makefile.am详解 实战Makefile.amMakefile.am是一种比Makefile更高层次的规则.只需指定要生成什么目标,它由什么源文件生成,要安装到什么目录等构成.表一列出了可执行 ...