Dertouzos

Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1415    Accepted Submission(s): 443

Problem Description
A positive proper divisor is a positive divisor of a number n, excluding n itself. For example, 1, 2, and 3 are positive proper divisors of 6, but 6 itself is not.

Peter has two positive integers n and d. He would like to know the number of integers below n whose maximum positive proper divisor is d.

 
Input
There are multiple test cases. The first line of input contains an integer T (1≤T≤106), indicating the number of test cases. For each test case:

The first line contains two integers n and d (2≤n,d≤109).

 
Output
For each test case, output an integer denoting the answer.
 
Sample Input
9
10 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
100 13
 
Sample Output
1
2
1
0
0
0
0
0
4
 
Source
 

一:直接暴力,这种方法是存在缺点的,可能会被卡数据。

#include<iostream>
#include<stdio.h>
using namespace std;
const int maxx=;
bool flag[maxx];
int prime[maxx];
int main(){
int cnt=;
for(int i=;i<maxx;i++){
if(!flag[i]){
for(int j=i<<;j<maxx;j+=i){
flag[j]=;
}
prime[cnt++]=i;
} }
// for(int i=0;i<100;i++) cout<<prime[i]<<endl;
int t;
scanf("%d",&t);
int n,d;
while(t--){
scanf("%d%d",&n,&d);
int ans=;
for(int i=;i<=cnt-&&prime[i]<=d&&prime[i]*d<n;i++){
if(d%prime[ans]==){
break;
}
ans++;
}
if(prime[ans]>d||prime[ans]*d>=n);
else ans++;
printf("%d\n",ans);
}
return ;
}

二、官方题解

Dertouzos

随便推导下, 令y=xdy=xd, 如果dd是yy的maximum positive proper divisor, 显然要求xx是yy的最小质因子. 令mp(n)mp(n)表示nn的最小质因子, 那么就有x \le mp(d)x≤mp(d), 同时有y < ny<n, 那么x \le \lfloor \frac{n-1}{d} \rfloorx≤⌊​d​​n−1​​⌋. 于是就是计算有多少个素数xx满足x \le \min{mp(d), \lfloor \frac{n-1}{d} \rfloor}x≤min{mp(d),⌊​d​​n−1​​⌋}.

当dd比较大的时候, \lfloor \frac{n-1}{d} \rfloor⌊​d​​n−1​​⌋比较小, 暴力枚举xx即可. 当dd比较小的时候, 可以直接预处理出答案. 阈值设置到10^6 \sim 10^710​6​​∼10​7​​都可以过.

hud 5750 Dertouzos的更多相关文章

  1. hdu 5750 Dertouzos 素数

    Dertouzos Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  2. BestCoder HDU 5750 Dertouzos

    Dertouzos 题意: 有中文,不说. 题解: 我看了别人的题解,还有个地方没懂, 为什么是 if(d%prime[i]==0) break; ? 代码: #include <bits/st ...

  3. HDU 5750 Dertouzos

    Dertouzos Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  4. HDU 5750 Dertouzos 简单数学

    感悟:这又是zimpha巨出的一场题,然后04成功fst(也就是这题) 实际上还是too young,要努力增加姿势, 分析:直接枚举这些数不好枚举,换一个角度,枚举x*d,也就是d的另一个乘数是多少 ...

  5. 题解报告:hdu 5750 Dertouzos(最大真约数、最小素因子)

    Problem Description A positive proper divisor is a positive divisor of a number n, excluding n itsel ...

  6. Dertouzos (5750)

    Dertouzos 题意: 就是给一个n和一个d,问有多少个小于n的数的最大因子是d. 分析: 如果一个数是质数,又和d互质,它们的乘积在范围内的话显然是满足条件的, 如果这个质数和d不互质,那么如果 ...

  7. 【HDU 5750】Dertouzos(数学)

    题目给定n和d,都是10的9次方以内,求1到n里面有几个数最大因数是d?1000000组数据.解:求出d的满足p[i]*d<n的最小质因数是第几个质数.即为答案. #include<cst ...

  8. 如何用Unity GUI制作HUD

    若知其所以然,自然知其然. HUD是指平视显示器,就是套在脸上,和你的眼睛固定在一起,HUD的意思就是界面咯,一般我们说HUD特指把3D空间中的界面的某些信息(比如血条,伤害之类)的贴在界面上,对应3 ...

  9. xamarin UWP平台下 HUD 自定义弹窗

    在我的上一篇博客中我写了一个在xamarin的UWP平台下的自定义弹窗控件.在上篇文章中介绍了一种弹窗的写法,但在实际应用中发现了该方法的不足: 1.当弹窗出现后,我们拖动整个窗口大小的时候,弹窗的窗 ...

随机推荐

  1. 精确率与回召率与 F1-Meature

    例子: true positive(真正例): 把 Colin power预测为Colin power(55) false positive(假正例): 把 其他人预测为Colin power(4+1 ...

  2. adb进阶知识,如何过滤只查看某一个app的日志

    前面大概学习了adb基础,但是adb的存在,在测试人员中究竟有什么必要,以及看log时,那么多的log,让我们看个屁啊,所以这一次,我决定一定要把adb这件事情搞清楚.   1.先来看最感兴趣的adb ...

  3. jQuery获取兄弟标签的文本

    // 一个div里面有一个span标签和多个button标签,每个button标签都有id,span标签没有id,通过点击其中一个button标签,来获取到span标签的text function ( ...

  4. Centos的yum源更换为阿里云源

    1.备份 # mv /etc/yum.repos.d/CentOS-Base.repo # /etc/yum.repos.d/CentOS-Base.repo.backup 2.下载新的CentOS- ...

  5. Practical Lessons from Predicting Clicks on Ads at Facebook (2014)论文阅读

    文章链接: https://quinonero.net/Publications/predicting-clicks-facebook.pdf abstract Facebook日活跃度7.5亿,活跃 ...

  6. oracle order by 自定义

    我们通常需要根据客户需求对于查询出来的结果给客户提供自定义的排序方式,那么我们通常sql需要实现方式都有哪些,参考更多资料总结如下(不完善的和错误望大家指出): 一.如果我们只是对于在某个程序中的应用 ...

  7. Test测试方法

    Junit 注解 解释 @Before 在每个测试方法运行前执行的方法 @After 在每个测试方法运行后执行的方法 @BeforeClass 在类中所有测试运行之前运行的方法 @AfterClass ...

  8. qt5---步长调节器SpinBox和QDoubleSpinBox

    #include <QSpinBox>            #include <QDoubleSpinBox> QSpinBox 用于整数的显示和输入,一般显示十进制数,也可 ...

  9. xpath的编写规则

    xpath的编写规则是// 表示从任意一级开始,或间隔任意级.换句话说中间就是可以隔很多层/ 从根目录开始,或从上一层的次层开始,就是需要跟上一层是上下级关系@id=aaa,id=aaa的元素,和元素 ...

  10. python 正则表达式实例

    字符匹配 实例 描述 python 匹配 "python". 字符类 实例 描述 [Pp]ython 匹配 "Python" 或 "python&qu ...