Codeforces Codeforces Round #319 (Div. 2) C. Vasya and Petya's Game 数学
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 数学的更多相关文章
- 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 ...
- 数学 - 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整除,系统会回答 ...
- Codeforces Round #319 (Div. 2) C. Vasya and Petya's Game 数学题
C. Vasya and Petya's Game ...
- 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 ...
- 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 ...
- 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
随机推荐
- poj3月题解
poj2110 二分答案+bfs判定 poj2112 二分答案+最大流判定(二分答案真乃USACO亲儿子) poj1986 裸的LCA,值得注意的是,树中任意两点的距离可以等于这两点到根的距离减去2* ...
- ORACLE SQLloader详细语法
Oracle SQL Loader的详细语法 SQL*LOADER是ORACLE的数据加载工具,通常用来将操作系统文件迁移到ORACLE数据库中.SQL*LOADER是大型数据 ...
- ejabberd中的http反向推送
http的反向推送通常使用"长轮询"或"长连接"的方式. 所谓"长轮询"是指客户端发送请求给服务器,服务器发现没有数据需要发送给客户端. h ...
- Simple XML
官网:http://simple.sourceforge.net/home.php 截止目前最新版本:simple-xml-2.7.1.jar 特点: jar lib文件只有360K左右的大小 它的使 ...
- 【Python】Python-用大写字母打印你的名字
与孩子一起编程,有个作业题:用大写字母打印你的名字. CCCC A RRRRR C C A A R R C A A R R C AAAAAAA RRRRR C C A A R R CCCC A A R ...
- <转>MySQL性能优化的最佳20+条经验
http://coolshell.cn/articles/1846.html 今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心 ...
- eclipse 项目报错问题
所有的问题在windoes-->show view--->Problems里查看
- wuzhicms上传弹出层,如何返回数据到当前页面?
我们要实现下面功能: 上传图片后,返回图片列表到页面: 点击开始上传后,自动返回结果到页面. 原理:通过openiframe打开上传弹出层. 其中: returntype 在这里是 2 www/res ...
- wuzhicms 无规律推荐位标签的嵌套使用
这种布局的页面,要做推荐位的话,往往需要做3个推荐位.但这样就得维护3个推荐位内容. 其实可以通过简单粗暴的方式 一个推荐位即可搞定. 如下代码: {wz:content action=" ...
- MySQL UNION 与 UNION ALL 语法与用法
MySQL UNION 语法 MySQL UNION 用于把来自多个 SELECT 语句的结果组合到一个结果集合中.语法为: SELECT column,... FROM table1 UNION [ ...