题意:一个游戏,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. SGU 114

    114. Telecasting station time limit per test: 0.25 sec. memory limit per test: 4096 KB Every city in ...

  2. UVA 10523 Very Easy!!!(大数据加法、乘法)

    题意:给出N,A,计算i*A^i(i=1~N)的和.1<=N<=30,0<=A<=15. 就是大数据运算,别的没什么,注意细节之处即可. 这题还要注意两个地方: 1.考虑A=0 ...

  3. 利用hadoop自带程序运行wordcount

    1.启动hadoop守护进程 bin/start-all.sh 2.在hadoop的bin目录下建立一个input文件夹 JIAS-MacBook-Pro:hadoop- jia$ mkdir inp ...

  4. POJ1258Agri-Net

    http://poj.org/problem?id=1258 题意 : john当上了镇长,打算给每个农场都连接网络,需要用最小的成本连接其他所有农场,所以要找最少的纤维连在一起,任何两个农场之间的距 ...

  5. PowerDesigner修改设计图中文字的字体大小等样式

    设计图中默认的字体是对英文比较合适的,中文就看不清楚了,特别不美观.但是可以通过修改“Display Preferences”适应我们的汉字. 我使用的PowerDesigner版本是15.1(测试版 ...

  6. 李洪强漫谈iOS开发[C语言-009] - C语言关键字

    // //  main.m //  04 - C语言关键字 // //  Created by vic fan on 16/7/12. //  Copyright © 2016年 李洪强. All r ...

  7. parent children

    class parent{ protected static int count=0; public parent() { count++; } } public class child extend ...

  8. REACTOS(193)与汇编编译器(69)的高人

    REACTOS(193)与汇编编译器(69)的高人http://blog.csdn.net/caimouse ReactOS编译成VS工程1: 首先从https://www.reactos.org/w ...

  9. Filter设计实现IP地址限制

    示例:创建一个IP过滤Filter,当一个用户发出访问请求的时候,首先通过过滤器进行判断, 如果用户的IP地址被限制,就禁止访问,只有合法的IP才可以继续访问.IP过滤Filter代码如下: IPFi ...

  10. 04-语言入门-04-Fibonacci数

    地址: http://acm.nyist.net/JudgeOnline/problem.php?pid=13    描述 无穷数列1,1,2,3,5,8,13,21,34,55...称为Fibona ...