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 && a2 >= a2k &&...
a3 >= a3k的数从原来的集合中分开。ai表示pi的幂。
那么只有当这个数的素因子的最大幂都被询问过一次,这个数才能确定。因此答案是所有的不大于n的只有一个素因子的数。
#include<bits/stdc++.h>
using namespace std; const int maxn = 1e3+;
int prime[maxn];
bool vis[maxn];
int sieve(int n)
{
int m = sqrt(n+0.5);
for(int i = ; i <= m; i++) if(!vis[i]){
for(int j = i*i; j <= n; j+=i) vis[j] = true;
}
int c = ;
for(int i = ; i <= n; i++) if(!vis[i]){
prime[c++] = i;
}
return c;
} vector<int> ans;
int main()
{
int tot = sieve();
int n; scanf("%d",&n);
for(int i = ; i < tot; i++){
int p = prime[i];
if(p > n) break;
for(int t = p; t<=n; t*=p){
ans.push_back(t);
}
}
printf("%d\n",ans.size());
for(int i = ; i < ans.size(); i++){
if(i) putchar(' ');
printf("%d",ans[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 数学题
C. Vasya and Petya's Game ...
- 构造水题 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, ...
- Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题
A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...
随机推荐
- c程序十六进制字符串转换为整数与反转
字符串转整数使用sscanf ; char *buf = "1d5ce"; sscanf (buf, "%x", &value); printf (&q ...
- 如何在VS2015中使用Git命令提示符
本文转载自 http://qkxue.net/info/176223/Visual-Studio-Git VS2015自带了Git插件,但有时候觉得Git控制台命令更方便些.VS中本身不能把Git B ...
- SQL Server(二)——语句 转
表的创建: 1.创建列(字段):列名+类型 2.设置主键列(primary key):能够唯一标识一条数据 3.设置唯一(unique):内容不能重复 4.外键关系:一张表(从表)其中的某列引用自另外 ...
- 一文带你认识Java8中接口的默认方法
Java8是Oracle于2014年3月发布的一个重要版本,其API在现存的接口上引入了非常多的新方法. 例如,Java8的List接口新增了sort方法.在Java8之前,则每个实现了List接口的 ...
- yii2之使用ueditor
代码效果: 1.去github下载yii2高级版ueditor扩展 2.将下载的扩展放入 /common/widgets 中(目录如图所示) 3.在视图中的代码 <?=common\widge ...
- MySQL下载与安装配置
一.Windows 上安装 MySQL Windows 上安装 MySQL 相对简单,最新版本下载地址: 官网:https://dev.mysql.com/downloads/mysql/ 下载步骤: ...
- HBase中报错 java.lang.NoClassDefFoundError: com/google/protobuf/LiteralByteString
Protobuf(全称 Protocol Buffers)是 Google 开发的一种数据描述语言,能够将结构化数据序列化,可用于数据存储.通信协议等方面.在 HBase 里面用使用了 Protobu ...
- thinkPHP5 tablib标签库自定义方法
具体可以参照thinkphp\library\think\template\taglib\Cx.php这里面的写法我在common模块下新建了一个文件夹taglib,新建了一个Test.php文件 n ...
- 【VueJS】VueJS开发请求本地json数据的配置
VueJS开发请求本地json数据的配置,旧版本是build/dev-server.js,新版本是build/webpack.dev.conf.js. VueJS开发请求本地json数据的配置,早期的 ...
- <pre></pre>标签自动换行
原文地址:https://www.cnblogs.com/qq78292959/p/4193142.html pre { white-space: pre-wrap; word-wrap: bre ...