hdu 5750 数论

部署运行你感兴趣的模型镜像

                                                   Dertouzos

A positive proper divisor is a positive divisor of a number nn, excluding nn itself. For example, 1, 2, and 3 are positive proper divisors of 6, but 6 itself is not. 

Peter has two positive integers nn and dd. He would like to know the number of integers below nn whose maximum positive proper divisor is dd.

Input

There are multiple test cases. The first line of input contains an integer TT (1≤T≤106)(1≤T≤106), indicating the number of test cases. For each test case: 

The first line contains two integers nn and dd (2≤n,d≤109)(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

题意:存在多少个小于n的数,是的其最大的因子为d;

通过最后一组样例发现 13*4,13*6;是不行的,所以就是要找有多少小于d的质数是的d*x< n;

但是假如 d是合数 如26,在这选到13就不能继续往下选了,下一个素数17能组成的因子可以是 17*2;明显比26大;

所以质数只能选到d能整除的数;

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int INF=0x3f3f3f3f;
const int maxn=1e7+5;
const int MOD=998244353;
long long n,d;
vector<int> v;
bool vis[maxn];
int p[maxn];
void Prime()
{
    for(int i=2;i<maxn;++i)
    {
        if(!vis[i]) v.push_back(i);
        for(int j=0;j<v.size()&&v[j]*i<maxn;++j)
        {
            vis[i * v[j]] = 1;
            if(i % v[j] == 0) break;
        }
    }
    for(int i=2;i<maxn;++i)
    {
        if(!vis[i]) p[i]=1;
        p[i]+=p[i-1];
    }
}
int main()
{
    int fuck;
    cin>>fuck;
    Prime();
    while(fuck--)
    {
        int ans=0;
        scanf("%lld%lld",&n,&d);
        for(int i=0;i<v.size();++i)
        {
            if(d*v[i]>=n) break;
            ++ans;
            if(d%v[i]==0) break;
        }
        cout<<ans<<endl;
    }
}

您可能感兴趣的与本文相关的镜像

Qwen3-8B

Qwen3-8B

文本生成
Qwen3

Qwen3 是 Qwen 系列中的最新一代大型语言模型,提供了一整套密集型和专家混合(MoE)模型。基于广泛的训练,Qwen3 在推理、指令执行、代理能力和多语言支持方面取得了突破性进展

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值