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. appium 自动化测试环境搭建

    最近再学习appium,把学习的过程记录下来,以防止到时候 换个电脑就不知道这么安装搭建appium环境了. 环境搭建: 0.JDK环境是必备的,这里大家自行百度,   1.安装 node 环境,前辈 ...

  2. 七,ingress及ingress cluster

    目录 Service 类型 namespace 名称空间 Ingress Controller Ingress Ingress-nginx 进行测试 创建对应的后端Pod和Service 创建 Ing ...

  3. svn 权限设置

    /***********************************************************/ //SVNSubversion 用户权限管理 //资料来源:网络.总结 // ...

  4. nginx-轮询、权重、ip_hash 、fair模式

    在 linux 下有 Nginx.LVS.Haproxy 等等服务可以提供负载均衡服 务,而且 Nginx 提供了几种分配方式(策略): 1.轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器 ...

  5. redis 加锁与释放锁(分布式锁1)

    使用Redis的 SETNX 命令可以实现分布式锁 SETNX key value 返回值 返回整数,具体为 - 1,当 key 的值被设置 - 0,当 key 的值没被设置 分布式锁使用 impor ...

  6. cmd命令行显示中文乱码

    cmd命令行显示中文乱码多数是由于字符编码不匹配导致. 1.查看cmd编码方式 方法一.打开cmd,输入chcp命令回车(显示默认编码:活动代码页:936指GBK) 方法二.打开cmd在标题栏单击鼠标 ...

  7. linux学习:【第4篇】之nginx

    一.知识点回顾 临时:关闭当前正在运行的 /etc/init.d/iptables stop 永久:关闭开机自启动 chkonfig iptables off ll /var/log/secure # ...

  8. Java——静态代理、动态代理

    https://blog.csdn.net/giserstone/article/details/17199755 代理的作用:业务类只需要关注业务逻辑本身,保证了业务类的重用性 一 静态代理 特点: ...

  9. node的安装和配置教程

    node,除了做数据服务处理,还是各大框架的环境依赖,作为前端开发人员,node是必不可少的.好了,接下来直接开始. 一.根据自己的安装环境(即你的电脑系统版本)下载对应安装包,官网地址:https: ...

  10. HTTP 请求出现 405 not allowed 的一种解决办法

    问题:http post请求网页会出现405 原因: Apache.IIS.Nginx等绝大多数web服务器,都不允许静态文件响应POST请求 解决:将post请求改为get请求