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. Hive简介

    实验简介 我们本节课程主要介绍 Hive 的相关知识,将会涉及以下内容: Hive 的定义 Hive 的体系结构 Hive 与关系数据库的区别 Hive 的应用场景 Hive 的存储 一.什么是 Hi ...

  2. 记一次Sql优化过程

    这几天在写一个存储过程,反复优化了几次,从最开始的7分钟左右,优化到最后的几秒,并且这个过程中我的导师帮我指点了很多问题,这些指点都是非常宝贵的,独乐乐不如众乐乐,一起来分享这次的优化过程吧. 这个存 ...

  3. Gentoo源码安装图解

    Gentoo源码安装 一.前期准备 (1)下载以下三个文件 二.配置安装环境 (1)用光盘引导到LiveCD环境 (2)配置当前LiveCD环境的网络 安装Gentoo时,服务器引导的LiveCD环境 ...

  4. 学习面试题Day06

    1.字节流的处理方式 字节流处理的是计算机最基本的单位byte,它可以处理任何数据格式的数据.主要的操作对象就是byte数组,通过read()和write()方法把byte数组中的数据写入或读出. 2 ...

  5. [转] This function or variable may be unsafe

    原文:This function or variable may be unsafe,他大姨妈 错误提示: [Error]'fopen' This function or variable may b ...

  6. 《深入Java虚拟机学习笔记》- 第9章 垃圾收集

    一.Java内存组成 组成图 堆(Heap) 运行时数据区域,所有类实例和数组的内存均从此处分配.Java虚拟机启动时创建.对象的堆内存由称为垃圾回收器的自动内存管理系统回收. 组成 组成 详解 Yo ...

  7. MEF技术

    MEF 是一个使开发人员能够创建“插件式应用程序”的技术,这里的“插件”是指在应用程序部署后开发人员能够通过开发“插件”来扩展应用程序功能.但不同之处是使用MEF框架您在系统设计阶段不需要考虑在应用程 ...

  8. Codeforces 628D 数位dp

    题意:d magic number(0<=d<9)的意思就是一个数,从最高位开始奇数位不是d,偶数位是d 题目问,给a,b,m,d(a<=b,m<2000)问,a,b之间有多少 ...

  9. STM32 USB-HID通信移植步骤

    大家可以使用压缩包中的UsbApp.exe调试本软件idVendor为:0483  idProduct为5750. 今天太晚了,明天还要上半天班,上位机软件找个时间在写一篇文章.请关注我的博客.压缩包 ...

  10. 0R电阻作用

    0欧电阻的作用(网上收集整理的) 0欧的电阻大概有以下几个功能:  ①做为跳线使用.这样既美观,安装也方便.  ②在数字和模拟等混合电路中,往往要求两个地分开,并且单点连接.我们可以用一个0欧的电阻来 ...