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. Delphi Timer组件

  2. BLE 5协议栈-物理层

    文章转载自:http://www.sunyouqun.com/2017/04/page/4/ 1. 简介 物理层(Physical Layer)是BLE协议栈最底层,它规定了BLE通信的基础射频参数, ...

  3. Linux 指令总结

    1. 显示本机信息 显示ip地址 hostname -i 显示当前使用用户 whoani 显示cpu信息 lscpu

  4. 第三次java测验2

    package java3; public class Suiji { public long a=12345L;//定义long类型的a,b,c变量 public long c=12345L; pu ...

  5. WebView net::ERR_CLEARTEXT_NOT_PERMITTED&&net::ERR_INTERNET_DISCONNECTED

    参照博客:https://blog.csdn.net/qq_33721320/article/details/84400825 测试Android 中WebView功能时,发现了这个问题: 解决的方式 ...

  6. iOS中为控件设置颜色渐变和透明度渐变

    项目中用到地图设置渐变色,查找资料找到两种方法:一种设置颜色,一种设置透明度: //为颜色设置渐变效果: UIView *view = [[UIView alloc] initWithFrame:CG ...

  7. Spring MVC 文件上传简单示例(form、ajax方式 )

    1.Form Upload SpringMVC 中,文件的上传是通过 MultipartResolver 实现的,所以要实现上传,只要注册相应的 MultipartResolver 即可. Multi ...

  8. 查看Spring MVC 父容器和子容器的对象的实例

    话不多说,直接上案例 package com.oukele.web; import org.springframework.beans.factory.annotation.Autowired; im ...

  9. vs code 写VUE代码 注释 html出现 //

    装个插件 "Vuter" 解决

  10. 22. ClustrixDB 杀掉恶意会话

    ClustrixDB提供了几种机制来识别消耗大量系统资源的查询.这样的查询通常是应用程序索引不良或错误的结果. ClustrixDB支持以下语法来杀死查询: KILL [QUERY | CONNECT ...