Codeforces Round #319 (Div. 2) C. Vasya and Petya's Game 数学
1 second
256 megabytes
standard input
standard output
Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number y?".
The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no questions), and then Vasya responds to each question with a 'yes' or a 'no'. After receiving all the answers Petya should determine the number that Vasya thought of.
Unfortunately, Petya is not familiar with the number theory. Help him find the minimum number of questions he should ask to make a guaranteed guess of Vasya's number, and the numbers yi, he should ask the questions about.
A single line contains number n (1 ≤ n ≤ 103).
Print the length of the sequence of questions k (0 ≤ k ≤ n), followed by k numbers — the questions yi (1 ≤ yi ≤ n).
If there are several correct sequences of questions of the minimum length, you are allowed to print any of them.
4
3
2 4 3
6
4
2 4 3 5
题意:给你一个数n,你给k个数,告诉你整除不整除,用最少的数确定那个数;
思路:根据唯一分解定理,利用素数和素数的次方即可,详见代码;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e2+,M=1e6+,inf=1e9+;\
int prime(int n)
{
if(n<=)
return ;
if(n==)
return ;
if(n%==)
return ;
int k, upperBound=n/;
for(k=; k<=upperBound; k+=)
{
upperBound=n/k;
if(n%k==)
return ;
}
return ;
}
int p[],flag;
int ans[];
int main()
{
int x,y,z,i,t;
flag=;
for(i=;i<;i++)
if(prime(i))
p[flag++]=i;
scanf("%d",&x);
int ji=;
for(i=;i<flag;i++)
{
if(x<p[i])break;
int base=p[i];
while(x>=base)
{
ans[ji++]=base;
base*=p[i];
}
}
printf("%d\n",ji);
for(i=;i<ji;i++)
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. 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 #319 (Div. 2) C Vasya and Petya's Game (数论)
因为所有整数都能被唯一分解,p1^a1*p2^a2*...*pi^ai,而一次询问的数可以分解为p1^a1k*p2^a2k*...*pi^aik,这次询问会把所有a1>=a1k &&am ...
- 构造水题 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 ...
随机推荐
- iOS - 开发中调试小技巧
对于软件开发而言,调试是必须学会的技能,重要性不言而喻.对于调试的技能,基本上是可以迁移的,也就是说你以前在其他平台上掌握的很多调试技巧,很多也是可以用在iOS开发中.不同语言.不同IDE.不同平台的 ...
- 香港主机Squid+Stunnel代理搭建
1.说明 Squid,代理软件 Stunnel,数据包加密(貌似如果数据不加密,客户端的数据流无法传到squid服务端,原因你懂的!) 2.Squid安装略 3.安装完squid后需要以下操作 a.生 ...
- 详解Go语言中的屏蔽现象
在刚开始学习Go语言的过程中,难免会遇到一些问题,尤其是从其他语言转向Go开发的人员,面对语法及其内部实现的差异,在使用Go开发时也避免不了会踩"坑".本文主要针对Go设计中的屏蔽 ...
- Centos6与Centos7的区别
前言 centos7与6之间最大的差别就是初始化技术的不同,7采用的初始化技术是Systemd,并行的运行方式,除了这一点之外,服务启动.开机启动文件.网络命令方面等等,都说6有所不同.让我们先来了解 ...
- You don't have permission to access
局域网内配置Discuz,web端访问server端,出现以下反馈: Forbidden You don't have permission to access / on this server. 网 ...
- Oracle 11g R2 RAC 高可用连接特性
转自-阿里巴巴许春值 1.scan概念 什么叫 SCAN,SCAN (Single Client Access Name) 是 Oracle 从11g R2 开始推出的,客户端可以通过 SCAN 特性 ...
- flask实现api
https://www.cnblogs.com/vovlie/p/4178077.html from flask import Flask, jsonify app = Flask(__name__) ...
- android 第三方框架
1.视频:jcvideoplayer 2.圆角:cardview 3.圆形头像:circleimageview 4.加载网络图片:universalimageloader 5.网络请求:xutils ...
- 【工具】代码生成器-python脚本
我觉得造轮子这件事情,是谁都可以做的.只不过做得好或者不好而已,用心了做得就要优雅一点. 之前用过java的代码生成器,什么pojodobodbo都能生成,于是我也来自己造一个轮子. 造轮子的事情是没 ...
- django高级之点赞、文章评论及上传文件
目录: 点赞 文章评论 上传文件 保留页面条件 一.点赞 1.所用技术: django model F查询 js应用:$(function () {}); 为文件加载完成执行ready() 方法.等同 ...