码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5750 Dertouzos 素数

时间:2016-08-29 17:39:51      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

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
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 素数

标签:

原文地址:http://www.cnblogs.com/Przz/p/5818667.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!