因为所有整数都能被唯一分解,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 (数论)的更多相关文章

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

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

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

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

                                                     C. Vasya and Petya's Game                           ...

  5. 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root

    题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...

  6. Codeforces Round 319 # div.1 & 2 解题报告

    Div. 2 Multiplication Table (577A) 题意: 给定n行n列的方阵,第i行第j列的数就是i*j,问有多少个格子上的数恰为x. 1<=n<=10^5, 1< ...

  7. Codeforces Round #319 (Div. 2)

    水 A - Multiplication Table 不要想复杂,第一题就是纯暴力 代码: #include <cstdio> #include <algorithm> #in ...

  8. codeforces 576a//Vasya and Petya's Game// Codeforces Round #319 (Div. 1)

    题意:猜数游戏变种.先选好猜的数,对方会告诉你他想的那个数(1-n)能不能整除你猜的数,问最少猜几个数能保证知道对方想的数是多少? 对一个质数p,如果p^x不猜,那么就无法区分p^(x-1)和p^x, ...

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

随机推荐

  1. Razor与HTML混合输出陷阱与技巧

    3,Razor与HTML混合输出陷阱与技巧   属性名称误判 有时候我们必须让html内容与razor语句紧接在一起, eg:      您好,a先生 假设变量名称为ViewBag.Name, 您好, ...

  2. 推荐一款让你纵横Github的读码神器

    当我们想深入了解一个开源项目的时候,通常我们有以下几种姿势: 懒汉型 通过Web的方式,逐个的点击页面寻找和查看具体的源码内容. 优点:不依赖任何工具,无须任何额外的操作 缺点:效率低下,查找文件不便 ...

  3. 我的省选 Day -15

    Day  -15 23:22:45 还有十几天就要去参加省选啦~,今天开始写日记记录一下,所以今天是第负十五天. 今天是阶段考的第二天(由于奥赛不用考试的我7:30才慢悠悠地到机房 早上学习动态DP, ...

  4. JavaScript进阶 - 第4章 跟着我的节奏走(流程控制语句)

    第4章 跟着我的节奏走(流程控制语句) 4-1 做判断(if语句) if语句是基于条件成立才执行相应代码时使用的语句. 语法: if(条件) { 条件成立时执行代码} 注意:if小写,大写字母(IF) ...

  5. 常见的div布局面试题

    题目1:如何让一个子元素在父元素里水平垂直居中? 方法1 .box{width:400px;height:400px;background:#ccc;position:relative;} .chil ...

  6. 题解 BZOJ 1912 && luogu P3629 [APIO2010]巡逻 (树的直径)

    本来抄了篇题解,后来觉得题解都太不友好(我太菜了),一气之下自己打...一打打到第二天QAQ 首先什么边也不加时,总路程就是2*(n-1) 考虑k=1的时候,答案显然是2*(n-1)-直径+1=2*n ...

  7. Uva1377

    /* 在n个刻度和他们的差里挑不超过7个刻度,0是固定的,最大的刻度肯定是最大值,然后剩下的dfs挑. */ #include<bits/stdc++.h> #define inf 0x3 ...

  8. maven settings.xml linux

    <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Soft ...

  9. 硬盘MBR和GPT区别

    似乎人人都可以张嘴就说"我懂电脑",但是总有一些看起来完全不懂但实际上非常基础的东西让"懂"与"不懂"清晰地划清界限.比如UEFI+GPT就 ...

  10. java exception "file not found or file not exist"

    出现这种异常一般有两种原因,第一种就是文件真的不存在:第二种是权限问题,权限问题又分为文件本身的权限和包含它的文件夹的权限 比如 ~/aaa/bbb/ccc/ddd/eee.txt  只要 aaa , ...