Codeforces Round #319 (Div. 2) C. Vasya and Petya's Game 数学题
1 second
256 megabytes
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.
A single line contains number n (1 ≤ n ≤ 103).
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.
4
3
2 4 3
6
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.
题意:给你一个N,随意拿出一个数,每次你可以提问 x%y==0是否成立,y=(1....n),问你最少提问次数来确定这个任意数是什么
题解:素数必拿出来,素数倍数拿出来存下来就可以了
//
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<bitset>
#include<set>
#include<vector>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a));
#define memfy(a) memset(a,-1,sizeof(a))
#define TS printf("111111\n");
#define FOR(i,a,b) for( int i=a;i<=b;i++)
#define FORJ(i,a,b) for(int i=a;i>=b;i--)
#define READ(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define maxn 1001
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 >v;
int hashs[maxn];
int main()
{
mem(hashs);
hashs[]=;
int n=read();
for(int i=;i<=n;i++)
{
if(hashs[i])continue;
for(int j=i+i;j<=n;j+=i)
{
hashs[j]=;
}
}
for(int i=;i<=n;i++)
{
if(!hashs[i])
v.push_back(i);
}
int sizee=v.size();
for(int i=;i<sizee;i++)
{
int tmp=v[i];
while(tmp*v[i]<=n)
{
v.push_back(tmp*v[i]);
tmp=tmp*v[i];
} }
cout<<v.size()<<endl;
for(int i=;i<v.size();i++)
{
cout<<v[i]<<" ";
}
return ;
}
代码君
Codeforces Round #319 (Div. 2) C. Vasya and Petya's Game 数学题的更多相关文章
- 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/ ...
- 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 (数论)
因为所有整数都能被唯一分解,p1^a1*p2^a2*...*pi^ai,而一次询问的数可以分解为p1^a1k*p2^a2k*...*pi^aik,这次询问会把所有a1>=a1k &&am ...
- Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)
题目链接:http://codeforces.com/contest/460/problem/A A. Vasya and Socks time limit per test 1 second mem ...
- 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...
- Codeforces Round 319 # div.1 & 2 解题报告
Div. 2 Multiplication Table (577A) 题意: 给定n行n列的方阵,第i行第j列的数就是i*j,问有多少个格子上的数恰为x. 1<=n<=10^5, 1< ...
- Codeforces Round #319 (Div. 2)
水 A - Multiplication Table 不要想复杂,第一题就是纯暴力 代码: #include <cstdio> #include <algorithm> #in ...
- codeforces 576a//Vasya and Petya's Game// Codeforces Round #319 (Div. 1)
题意:猜数游戏变种.先选好猜的数,对方会告诉你他想的那个数(1-n)能不能整除你猜的数,问最少猜几个数能保证知道对方想的数是多少? 对一个质数p,如果p^x不猜,那么就无法区分p^(x-1)和p^x, ...
随机推荐
- xingo的demo部署
1)安装go 2)安装git xingo默认使用google protobuf来进行序列化和反序列化操作,所以需要安装 go get github.com/golang/protobuf/proto ...
- Spring boot 配置tomcat后 控制台不打印SQL日志
在pom.xml中配置tomcat启动处加上: <dependency> <groupId>org.springframework.boot</groupId> & ...
- Java 调用存储过程 返回结果集
这里使用Oracle数据库的thin连接. 下面是存储过程SQL 1 createorreplaceprocedure proc3(stid in student.stuid%type, stname ...
- docker centos7 配置和宿主机同网段IP
docker centos7 配置和宿主机同网段IP 1.安装brctl 命令 # yum -y install bridge-utils 2.编辑网卡配置文件 # vi ifcfg-eno16777 ...
- codevs1288 埃及分数
题目描述: 在古埃及,人们使用单位分数的和(形如1/a的, a是自然数)表示一切有理数. 如:2/3=1/2+1/6,但不允许2/3=1/3+1/3,因为加数中有相同的. 对于一个分数a/b,表示方法 ...
- Project Euler
Euler 34 答案:40730 我用程序算了无数次都是145,蛋疼,最后拿别人的程序仔细对比…… 原来 !=…… 真蛋疼,我竟然连基础数学都忘了 Euler-44 根据公式容易得出:Pmin + ...
- U盘启动盘制作工具(安装Linux)
2018-09-15 17:36:42 1. Etcher 官网:https://etcher.io/ 资料来源:https://linuxmint-installation-guide.readt ...
- python 库文件版本收集及安装
版本收集:pip freeze > require.txt版本安装:pip install -r require.txt
- JS 去除字符串空格
$.trim()是jQuery提供的函数,用于去掉字符串首尾的空白字符. "abc 123 def".replace(/\s/g, "") 去除所有的空格
- [luoguP1011] 车站(递推)
传送门 蒟蒻我关系式没有找出来. 直接模拟递推过程好了. 代码 #include <cstdio> #define N 21 int a, n, m, x, y; int up[N][2] ...