hdu 5750——Dertouzos(简单)

来源:互联网 发布:unity3d 手游源码 编辑:程序博客网 时间:2024/06/07 09:39

Problem Description
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.

题目大意:正整数x称为n的positive proper divisor, 当且仅当x | n并且1≤ x 且n>x。 例如, 1, 2, 和3是6的positive proper divisor, 但是6不是
Peter给你两个正整数n和d. 他想要知道有多少小于n的整数, 满足他们的最大positive proper divisor恰好是d.

题解:对于每个整数,它乘以的数必须都小于等于它的最小因数,这样才能保证其满足条件。

#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>using namespace std;const int maxn = 100000 + 130;const int maxm = 1e5+120;int prime[maxn];bool vis[maxm]; int mind[maxn];int n,d,cnt;void get_prime(int n){    memset(vis,0,sizeof(vis));    memset(mind,0,sizeof(mind));    vis[1]=1;cnt=0;    for(int i=2;i * i<n;i++){        if(vis[i]) continue;        else mind[i] = i;        for(int j=i*i;j<n;j+=i){            vis[j]= 1;            if(!mind[j]) mind[j]=i;            }    }    for(int i=2;i<n;i++) if(!vis[i]) prime[++cnt]=i;}int main(){    int kase;scanf("%d",&kase);    get_prime(maxm-10);    while(kase--){        scanf("%d%d",&n,&d);        if(d>=n) {printf("0\n");continue;}        int ans = 0 ;        int maxnum = min(d,(n-1)/d);        for(int i=1;i<=cnt;i++){            if(prime[i]*d>=n) break;            ans++;            if(d%prime[i]==0) break;        }        printf("%d\n",ans);    }    return 0;}
0 0