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 ...
随机推荐
- 封装类似thinkphp连贯操作数据库的Db类(简单版)。
<?php header("Content-Type:text/html;charset=utf-8"); /** *php操作mysql的工具类 */ class Db{ ...
- Fitnesse框架简单介绍
1.Fitnesse是什么? 官方的说明:FitNesse is a wiki server. It's also a test execution engine. Fitnesse是一个wiki s ...
- linux和windows下安装python拓展包及requirement.txt安装类库
python拓展包安装 直接安装拓展包默认路径: Unix(Linux)默认路径:/usr/local/lib/pythonX.Y/site-packagesWindows默认路径:C:\Python ...
- tidb 安装deploy-ntp.yml失败,什么原因?
在同步时间服务的时候报错,信息如下.实际上我配置的时间服务器的IP就是如下的10.188.100.103,在 执行$ansible-playbook -i hosts.ini deploy_ntp.y ...
- nginx 初了解
随着现代web开发的发展,restful,前后端分离,前端js框架的应用越来越普遍.很多web应用请求的接口可能根本就存在于不同的服务器,类似于微信,支付宝等等.这其中就会存在跨域的问题.简单来说,跨 ...
- 重启centOS丢失nginx.pid导致无法启动nginx的解决方法
目录 找到nginx 找到nginx的配置文件 拼接命令,启动nginx Nginx指令拓展知识(中英对照): tags: centOS linux nginx categories: 服务器 找到n ...
- SpringBoot2.0 基础案例(07):集成Druid连接池,配置监控界面
一.Druid连接池 1.druid简介 Druid连接池是阿里巴巴开源的数据库连接池项目.Druid连接池为监控而生,内置强大的监控功能,监控特性不影响性能.功能强大,能防SQL注入,内置Login ...
- 【poj3764】The xor-longest Path
The xor-longest Path Description In an edge-weighted tree, the xor-length of a path p is defined as ...
- MySQL数据库 (5)
--视图,触发器,函数,存储过程,事务,索引
- Windows和Ubuntu使用网线直连搭建局域网
1.Windows下的配置:右键右下角的网络图标(或者右键网络→属性)→更改适配器设置→以太网→右键属性→TCP/IPv4→IP地址(192.168.1.3)→子网掩码(255.255.255.0)→ ...