Dertouzos

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

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
/*
hdu 5750 Dertouzos 素数 problem:
求n里面最大约数(不包含自身)为d的个数 solve:
如果是最大约数,那么另一个数必定数质数. 所以就是求最大的质数x,满足 x*d<n
但是有可能d的最小质数比x小: 4000 1000 ---> x = 3. 但实际上当x = 3时, 3*1000 = 3000 = 2*1500
所以还要求d的最小质数,最较小的即可. hhh-2016-08-29 16:46:41
*/
#pragma comment(linker,"/STACK:124000000,124000000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define lson i<<1
#define rson i<<1|1
#define ll long long
#define clr(a,b) memset(a,b,sizeof(a))
#define scanfi(a) scanf("%d",&a)
#define scanfl(a) scanf("%I64d",&a)
#define key_val ch[ch[root][1]][0]
#define inf 1e9
using namespace std;
const ll mod = 1e9+7;
const int maxn = 1000005; int prime[maxn+100];
void get_prime()
{
clr(prime,0);
for(int i =2; i <= maxn; i++)
{
if(!prime[i]) prime[++prime[0]] = i;
for(int j = 1; j <= prime[0] && prime[j] <= maxn/i; j++)
{
prime[prime[j]*i] = 1;
if(i%prime[j] == 0) break;
}
}
} int main()
{
int T,n,d;
int ans,tans;
get_prime();
scanfi(T);
while(T--)
{
scanfi(n),scanfi(d);
int limit = min(d,n/d); tans = ans = 0;
if(prime[1] * d >= n)
{
printf("0\n");
continue;
}
for(int i = 1; i <= prime[0]; i++)
{
if(d % prime[i] == 0)
{
ans = i;
break;
}
else
{
if(prime[i]*d < n && prime[i+1]*d >= n)
{
ans = i;
break;
}
}
}
printf("%d\n",ans);
}
return 0;
}

  

hdu 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 简单数学

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

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

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

  5. HDU 4548 美素数(打表)

    HDU  4548  美素数(打表)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88159#problem/H 题目 ...

  6. 【HDU 5750】Dertouzos(数学)

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

  7. HDU 4548 美素数 在线打表加数状数组

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4548 解题报告:一开始本想先打个素数表,然后每次输入L 跟R 的时候都进行暴力判断,但这题测试数据太多 ...

  8. ZOJ 2562 HDU 4228 反素数

    反素数: 对于不论什么正整数x,起约数的个数记做g(x).比如g(1)=1,g(6)=4. 假设某个正整数x满足:对于随意i(0<i<x),都有g(i)<g(x),则称x为反素数. ...

  9. hud 5750 Dertouzos

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

随机推荐

  1. 201421123042 《Java程序设计》第2周学习总结

    1. 本周学习总结 以几个关键词描述本周的学习内容.并将关键词之间的联系描述或绘制出来. 原则:少而精,自己写.即使不超过5行也可,但请一定不要简单的复制粘贴. 引用类型 引用类型是指向一个对象,感觉 ...

  2. Android类加载机制及热修复实现

    Android类加载机制 Dalvik虚拟机如同其他Java虚拟机一样,在运行程序时首先需要将对应的类加载到内存中.而在Java标准的虚拟机中,类加载可以从class文件中读取,也可以是其他形式的二进 ...

  3. 改变input的placeholder颜色

    input::-webkit-input-placeholder{ color:#666; } input::-ms-input-placeholder{ color:#666; } input::- ...

  4. Python之旅.第三章.函数3.26

    一.函数: 1.为什么要有函数?什么是函数? 1.组织结构不清晰,可读性差 2.代码冗余 3.管理维护的难度极大,扩展性 具备某一个功能的工具就是程序的中函数 事先准备工具的过程---->函数的 ...

  5. 微信号的openid的深入理解

    header('Location:https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$this->appid.'&r ...

  6. Linux命令及lamp搭建

    单纯属于Linux的命令:1.强制卸载有依赖关系的软件包: rpm -e httpd-2.2.15-26.el6.x86_64 --nodeps(--nodeps表示无依赖)4.删除当前目录所有的文件 ...

  7. IDEA插件和快捷设置

    前言 IDEA全名Intellij IDEA,是Java开发的集成环境,它有两个版本,专业版(Ultimate)和社区版(Community),专业版需要注册,而社区版不用注册,同时需要注意的是社区版 ...

  8. Mybatis的mapper代理开发dao方法

    看完了之前的mybatis原始的dao开发方法是不是觉得有点笨重,甚至说没有发挥mybatis 作为一个框架的优势.总结了一下,原始的dao方法有以下几点不足之处 dao接口实现方法中存在大量的模板方 ...

  9. java 细说String

    String类内部用一个字符数组表示字符串,实例变量定义为: private final char value[]; String有两个构造方法,可以根据char数组创建String public S ...

  10. ELK学习总结(2-1)mavel -》sense 和 索引初始化

    1.安装 sudo  elasticsearch/bin/plugin -install elasticsearch/mavel/latest http://localhost:9200/_plugi ...