题意:一个游戏,A童鞋在1~n的范围里猜一个数,B童鞋询问一个集合,A童鞋要对集合里每个数做出回答,他猜的数能否给整除,B要通过这些答案得到A猜的数,最少需要猜哪些数?

解法:一个数可以由若干个质数的指数次幂相乘得到,所以只要询问小于n的所有质数的指数次幂就可以得到全部数的答案。

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long using namespace std; vector <int> prime;
void init()
{
bool isprime[1005] = {0};
for(int i = 2; i <= 1000; i++)
{
if(!isprime[i])
{
prime.push_back(i);
for(int j = i + i; j <= 1000; j += i) isprime[j] = 1;
}
}
}
int main()
{
init();
int n;
while(~scanf("%d", &n))
{
vector <int> ans;
for(int i = 0; i < prime.size(); i++)
{
int tmp = prime[i];
while(tmp <= n)
{
ans.push_back(tmp);
tmp *= prime[i];
}
}
cout << ans.size() << endl;
for(int i = 0; i < ans.size(); i++)
{
if(i) printf(" ");
cout << ans[i];
}
puts("");
}
return 0;
}

  

CF 577C Vasya and Petya's Game的更多相关文章

  1. CodeForces 577C Vasya and Petya's Game 数学

    题意就是给你一个1到n的范围 你每次可以问这个数是否可以被某一个数整除 问你要猜多少数才能确定这个数…… 一开始一点思路也没有 后来查了一下才知道 每个数都可以分为几个质数的整数次幂相乘得到…… #i ...

  2. 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/ ...

  3. 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 ...

  4. 数学 - 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整除,系统会回答 ...

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

                                                     C. Vasya and Petya's Game                           ...

  6. 【CodeForces 577C】Vasya and Petya’s Game

    链接 某个数x属于[1,n],至少询问哪些数“x是否是它的倍数”才能判断x.找出所有质因数和质因数的幂即可. #include<cstdio> #include<algorithm& ...

  7. CF576A Vasya and Petya's Game

    题目大意: 给定一个数字 n,现在 Vasya 要从 1∼n 中想一个数字 x. Petya 向 Vasya 询问 "x 是否能整除 y?" ,通过 Vasya 的回答来判断 x ...

  8. CF 1073C Vasya and Robot(二分答案)

    C. Vasya and Robot time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  9. cf C. Vasya and Robot

    http://codeforces.com/contest/355/problem/C 枚举L和R相交的位置. #include <cstdio> #include <cstring ...

随机推荐

  1. 安卓 unit 测试与 instrument 测试的代码共享

    假如你有一款安卓应用,其包含一系列测试类,其中一部分是unit 测试(位于 src/test),其余为instrument 测试(位于 src/androidTest). 那么问题来了:你有一些想在所 ...

  2. C++中的const关键字

    http://blog.csdn.net/eric_jo/article/details/4138548 C++中的const关键字的用法非常灵活,而使用const将大大改善程序的健壮性,本人根据各方 ...

  3. C#操作config文件

    以下是app.config或web.config的定义,定义了一个参数,键为Isinit,值为false <?xml version="1.0"?> <confi ...

  4. 【QT】视频播放+文件选择

    折腾了两个小时,太久没用了,找了半天的感觉. 先是在视频播放 的代码基础上加选择视频的按钮,开始总是显示两个框,后来发现需要用QSplitter来实现同时有多个框的情况. 把中心窗口设为这个split ...

  5. C++ Variables and Basic Types Notes

    1. Type conversion: If we assign an out-of-range value to an object of unsigned type, the result is ...

  6. POJ 1191 棋盘分割(DP)

    题目链接 题意 : 中文题不详述. 思路 : 黑书上116页讲的很详细.不过你需要在之前预处理一下面积,那样的话之后列式子比较方便一些. 先把均方差那个公式变形, 另X表示x的平均值,两边平方得 平均 ...

  7. Ubuntu 14.04 + Linux 3.14.34 系统调用实现文件拷贝

    采用 64位系统, ubuntu 14.04 + 新内核linux-3.14.34 下载地址https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.1 ...

  8. 修改Eclipse字体

    选择菜单:Windows->Preferences->Genneral->Appearance->Colors and Font

  9. java.util.zip.ZipOutputStream压缩无乱码(原创)

    package io; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.FileI ...

  10. 我的第一个jquery插件:下拉多选框

    <!DOCTYPE HTML> <html> <head> <title> New Document </title> <meta n ...