• 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
    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
    ");
                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
    ",ans);
        }
        return 0;
    }
    

      

  • 相关阅读:
    Oracle学习(四)--sql及sql分类讲解
    Oracle学习(三)--数据类型及常用sql语句
    Oracle学习(二)--启动与关闭
    Tomcat学习笔记--启动成功访问报404错误
    有关Transaction not successfully started问题解决办法
    百度富文本编辑器UEditor1.3上传图片附件等
    hibernate+junit测试实体类生成数据库表
    js登录与注册验证
    SVN安装配置与使用
    [LeetCode] #38 Combination Sum
  • 原文地址:https://www.cnblogs.com/Przz/p/5818667.html
Copyright © 2020-2023  润新知