首页 > 代码库 > hdu 5750 Dertouzos 素数

hdu 5750 Dertouzos 素数

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 (1T106), indicating the number of test cases. For each test case:

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

 

Output
For each test case, output an integer denoting the answer.
 

 

Sample Input
910 210 310 410 510 610 710 810 9100 13
 

 

Sample Output
121000004

 

/*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 1e9using 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 素数