博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数学 - Codeforces Round #319 (Div. 1)A. Vasya and Petya's Game
阅读量:7012 次
发布时间:2019-06-28

本文共 1431 字,大约阅读时间需要 4 分钟。

Vasya and Petya's Game 


 

Mean: 

给定一个n,系统随机选定了一个数x,(1<=x<=n)。

你可以询问系统x是否能被y整除,系统会回答"Yes"or“No"。

问:至少询问多少次可以唯一确定x,并输出询问序列。(special judge).

analyse:

做法:求质数的整数次幂(不大于n)。

思路:首先我们肯定是用质数来判断,因为质数排除的是最多的。

如果质数p[i]能够整除,那么x有可能是p[i]^2,p[i]^3....。

Time complexity: O(N)

 

Source code: 

/*
* this code is made by crazyacking
* Verdict: Accepted
* Submission Date: 2015-09-11-16.33
* Time: 0MS
* Memory: 137KB
*/
#include <queue>
#include <cstdio>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <climits>
#include <map>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#define max(a,b) (a>b?a:b)
using
namespace
std;
typedef
long
long(
LL);
typedef
unsigned
long
long(
ULL);
const
double
eps(
1e-8);
const
int NN
=
100100;
int p
[NN
];
bool
v
[NN
];
int
num
=-
1;
void
makePrime()
{
     
int
i
,
j;
     
for(
i
=
2;
i
<NN;
++
i)
     
{
           
if(
!
v
[
i
])
{
p
[
++
num
]
=
i;
}
           
for(
j
=
0;
j
<=
num
&&
i
*p
[
j
]
<NN;
++
j)
           
{
                 
v
[
i
*p
[
j
]]
=
true;
                 
if(
i
%p
[
j
]
==
0)
{
break;
}
           
}
     
}
}
vector
<
int
>
ve;
int n;
int
main()
{
     
makePrime();
     
scanf(
"%d"
,
&n);
     
for(
int
i
=
0;
i
<
num;
++
i)
     
{
           
if(p
[
i
]
<=n)
           
{
                 
int
t
=p
[
i
];
                 
while(
t
<=n)
                 
{
                       
ve
.
push_back(
t);
                       
t
=
t
*p
[
i
];
                 
}
           
}
           
else
break;
     
}
     
int
si
=
ve
.
size();
     
printf(
"%d
\n
"
,
si);
     
for(
int
i
=
0;
i
<
si;
++
i)
           
printf(
i
==
si
-
1
?
"%d
\n
"
:
"%d "
,
ve
[
i
]);
     
return
0;
}
/*
*/

 

转载于:https://www.cnblogs.com/crazyacking/p/4801311.html

你可能感兴趣的文章
我的友情链接
查看>>
纯靠内链提权重
查看>>
linux因环境变量修改错误,造成命令查找不到,且无法登陆系统解决办法
查看>>
元芳,你怎么看,网络为何会如此流行!
查看>>
计算机运行命令全集
查看>>
Android项目之旅三 简易Mp3播放器从获取服务器端Mp3信息
查看>>
将一个数组中的奇元素全部移到数组的前半部分,即将奇偶元素分开
查看>>
无需SDK的统计工具,让哥赚了个iphone6
查看>>
没有做数据备份 网站随时毁于一旦
查看>>
Python学习笔记
查看>>
js中json与字符串转换小例子
查看>>
学习笔记-实验楼项目课(Linux桌面字典)
查看>>
Spring基础问答
查看>>
iOS8 相机拍照问题 Snapshotting a view
查看>>
comparable 接口的使用示例
查看>>
剑指Offer之重建二叉树(题6)
查看>>
strace-跟踪进程执行时的系统调用
查看>>
三个数找最大 1.0
查看>>
判断大端与小端
查看>>
计算机科学技术基础知识之多媒体知识
查看>>