Dertouzos

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

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
 
 
题意:如果 d 是k除了自身以外最大的因子, 在[2,n)内找有多少个数满足 最大的因子是 k .
题解:昨天想得太简单了,真是naive..我开始的想法是 将 min(d,(n-1)/d) 里面所有的质数算出来,然后天真的以为这就是结果...然后一直WA,忽视了一个很重要的条件,那就是我们的数中d一定是最大的因子,所以如果出现了能够将d整除的质数,那么我们就可以将d分解,从而得到一个更大的 d' ,所以说我们选择的质数是不能够将 d 除尽的.
#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long LL;
const int N = ;
bool p[N];
int prime[N];
int id;
void init()
{
id = ;
for(int i=; i<N; i++)
{
if(!p[i])
{
prime[++id] = i;
for(LL j=(LL)i*i; j<N; j+=i)
{
p[j] = true;
}
}
}
} int main()
{
init();
int tcase;
scanf("%d",&tcase);
while(tcase--)
{
int n,d;
scanf("%d%d",&n,&d);
int ans = ;
for(int i=; i<=id; i++)
{
if(prime[i]*d>=n) break;
ans++;
if(d%prime[i]==) break;
}
printf("%d\n",ans);
}
return ;
}

hdu 5750(数论)的更多相关文章

  1. hdu 5750 Dertouzos 素数

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

  2. GCD and LCM HDU 4497 数论

    GCD and LCM HDU 4497 数论 题意 给你三个数x,y,z的最大公约数G和最小公倍数L,问你三个数字一共有几种可能.注意123和321算两种情况. 解题思路 L代表LCM,G代表GCD ...

  3. HDU 4497 数论+组合数学

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4497 解题思路:将满足条件的一组x,z,y都除以G,得到x‘,y',z',满足条件gcd(x',y' ...

  4. hdu 4542 数论 + 约数个数相关 腾讯编程马拉松复赛

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4542 小明系列故事--未知剩余系 Time Limit: 500/200 MS (Java/Others) ...

  5. hdu 4961 数论?

    http://acm.hdu.edu.cn/showproblem.php?pid=4961 给定ai数组; 构造bi, k=max(j | 0<j<i,a j%ai=0), bi=ak; ...

  6. hdu 1664(数论+同余搜索+记录路径)

    Different Digits Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  7. hdu 3641 数论 二分求符合条件的最小值数学杂题

    http://acm.hdu.edu.cn/showproblem.php?pid=3641 学到: 1.二分求符合条件的最小值 /*================================= ...

  8. hdu 4059 数论+高次方求和+容斥原理

    http://acm.hdu.edu.cn/showproblem.php? pid=4059 现场赛中通过率挺高的一道题 可是容斥原理不怎么会.. 參考了http://blog.csdn.net/a ...

  9. 【HDU 5750】Dertouzos(数学)

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

随机推荐

  1. delphi RGB与TColor的转换

    1.RGB转换为Tcolor function RGBToColor(R,G,B: byte): Tcolor;begin  Result := B Shl 16 or G  shl 8 or R;e ...

  2. java 使用ByteArrayOutputStream和ByteArrayInputStream实现深拷贝

    首先介绍Java中的浅拷贝(浅克隆)和深拷贝(深克隆)的基本概念: 浅拷贝: 被复制对象的所有变量都含有与原来的对象相同的值,而所有的对其他对象的引用仍然指向原来的对象.浅复制仅仅复制所考虑的对象,而 ...

  3. Codeforces Round #518 Div. 1没翻车记

    A:设f[i][j][0/1]为前i个数第i位为j且第i位未满足/已满足限制的方案数.大力dp前缀和优化即可. #include<iostream> #include<cstdio& ...

  4. poj 1034 The dog task (二分匹配)

    The dog task Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2559   Accepted: 1038   Sp ...

  5. 【C++ troubleshooting】A case about decltype

    template <typename iter_t> bool next_permutation(iter_t beg, iter_t end) { // if (beg == end | ...

  6. 【题解】AHOI2009同类分布

    好开心呀~果然只有不看题解做出来的题目才会真正的有一种骄傲与满足吧ヾ(๑╹◡╹)ノ" 实际上这题只要顺藤摸瓜就可以了.首先按照数位dp的套路,有两维想必是省不掉:1.当前dp到到的位数:2. ...

  7. BZOJ 3545 / 洛谷 P4197 Peaks 解题报告

    P4197 Peaks 题目描述 在\(\text{Bytemountains}\)有\(N\)座山峰,每座山峰有他的高度\(h_i\).有些山峰之间有双向道路相连,共\(M\)条路径,每条路径有一个 ...

  8. BZOJ 4318: OSU! 期望概率dp && 【BZOJ3450】【Tyvj1952】Easy 概率DP

    这两道题是一样的...... 我就说一下较难的那个 OSU!: 这道15行的水题我竟然做了两节课...... 若是f[i][0]=(1-p)*f[i-1][0]+(1-p)*f[i-1][1],f[i ...

  9. 解决echarts中X轴文字过长的问题。【转】

    axisLabel: { interval: , formatter:function(value) { debugger var ret = "";//拼接加\n返回的类目项 ; ...

  10. E. Intercity Travelling

    E. Intercity Travelling time limit per test 1.5 seconds memory limit per test 256 megabytes input st ...