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, ...
随机推荐
- 复制Windows的等宽字体到Linux
1.从Windows的Fonts目录下复制字体 2.在Linux的/usr/share/fonts目录下创建子目录例如:sudo mkdir /usr/share/fonts/win 3.复制字体到该 ...
- iOS工具】rvm、Ruby环境和CocoaPods安装使用及相关报错问题解决
〇.前言 <p>在iOS开发中 CocoaPods作为库依赖管理工具就是一把利器. 有了 CocoaPods则无需再通过拖 第三方库及第三方库所依赖的 framework静态库到项目中等麻 ...
- 启动myeclipse弹窗Please allow Subclipse team to receive anonymous usage statistics for this Eclipse intance
Please allow Subclipse team to receive anonymous usage statistics for this Eclipse intance(翻译:请允许Sub ...
- router-link的使用方法
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- 浅谈树套树(线段树套平衡树)&学习笔记
0XFF 前言 *如果本文有不好的地方,请在下方评论区提出,Qiuly感激不尽! 0X1F 这个东西有啥用? 树套树------线段树套平衡树,可以用于解决待修改区间\(K\)大的问题,当然也可以用 ...
- HYSBZ - 2763 飞行路线(分层图最短路线)
题目: Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并且航线有一定的价 ...
- [Python3网络爬虫开发实战] 1.7.1-Charles的安装
Charles是一个网络抓包工具,相比Fiddler,其功能更为强大,而且跨平台支持得更好,所以这里选用它来作为主要的移动端抓包工具. 1. 相关链接 官方网站:https://www.charles ...
- PHP面向对象设计五大原则(SOLID)梳理总结
PHP设计原则梳理,参考<PHP核心技术与最佳实践>.<敏捷开发原则.模式与实践>,文章PHP面向对象设计的五大原则.设计模式原则SOLID 单一职责原则(Single Res ...
- insert,extend
#insert s = ['8','9','sfd',('45','00'),{'01':'56'}] s0 = [] while 1 : extend = input("请输入要添加的内容 ...
- jquery对JSON字符串的解析--eval函数
jquery eval解析JSON中的注意点介绍----https://www.jb51.net/article/40842.htm