hdu 5750 Dertouzos (素数+数学)

来源:互联网 发布:windows一键还原按什么 编辑:程序博客网 时间:2024/06/07 16:43

Dertouzos
Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1703 Accepted Submission(s): 537

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

The first line contains two integers n and d (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

首先,很明显,我们设一个数字k,求满足k*d

#include<iostream>using namespace std;#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<stdlib.h>#include<vector>#include<queue>#include<deque>#include<map>#include<set>#include<time.h>#define pi(x,y) printf("c",(x),(y));#define pin(x) printf("%d\n",(x));#define si(x) scanf("%d",&(x))#define sii(x,y) scanf("%d%d",&(x),&(y))#define s3(x,y,z) scanf("d%d",&(x),&(y),&(z))#define rep(x,y,z) for(int (x)=(y);(x)<(z);++(x))//#defien dep(x,y,z) for(int (x)=(y)-1;(x)>=(z);--(x))//#define sl(x) scanf("%lld",&(x))#define read int Tcase;scanf("%d",&Tcase);while(Tcase--)#define cls(x,y) memset((x),(y),sizeof((x)));#define cls0(x) memset((x),0,sizeof((x)));#define max3(value_a,value_b,value_c) max(max(value_a,value_b),value_c)#define GT(x) (x)=clock();typedef __int64 LL;//typedef unsigned long long ULL;//const int maxint=((~((unsigned)(0)))>>1);//const LL maxll=((~((unsigned long long)(0)))>>1);const int inf=0x3f3f3f3f;const double PI=acos(-1.0);const int maxn=8e6+5;//int a[maxn]const __int64 N = (LL)maxn;int a[maxn+10] = {0};int isNotPrime[N+10] = {1, 1};int minpri[maxn+10];char tt;int rt(int&data) {    while((tt=getchar())&&(tt>'9'||(tt<'0'))) {}    data=0;    do {        data=data*10+tt-'0';        tt=getchar();    } while(tt>='0'&&tt<='9');}int main() {#ifdef tangge    clock_t tSTART,tEND,t3;    GT(tSTART);#endif // tangge    cls(minpri,-1)    int num_prime=0;    for(int i = 2 ; i < N ; i++) {        if(! isNotPrime[i])            a[num_prime ++]=i,minpri[i]=i;        for(int j = 0 ; j < num_prime && (__int64)i * a[j] <  N ; j ++) {            isNotPrime[i * a[j]] = 1;            minpri[i*a[j]]=a[j];            if( !(i % a[j] ) )  //¹Ø¼ü´¦2                break;        }    }//    printf("%d\n",minpri[12]);//    printf("%d\n",minpri[49]);//    printf("%d\n",minpri[51]);//    printf("%d\n",minpri[1111]);//    cout<<num_prime<<endl;//    int len=vec.size();//freopen("out.txt","r",stdin);//freopen("out1.txt","w",stdout);    int n,m,tp;    read {        rt(n),rt(m);//        sii(n,m);        if(m>=n) {            puts("0");            continue;        }        --n;//        LL t=(LL)n;        tp=upper_bound(a,a+num_prime,n/m)-a;        --tp;//        cout<<"tp1="<<tp<<endl;        if(m<=maxn) {            int tt=upper_bound(a,a+num_prime,minpri[m])-a;            tp=min(tp,tt-1);        } else{            int nums=m;            for(int i=0; i<num_prime&&((__int64)a[i]*m<=(__int64)n); ++i) {                if(m%a[i]==0) {                    nums=a[i];                    break;                }            }            int tt=upper_bound(a,a+num_prime,nums)-a;            tp=min(tp,tt-1);        }//        int val=m;//        ,lens=(int)sqrt(1.0*m);//        for(int i=0; i<num_prime&&a[i]<=lens; ++i) {//            if(m%a[i]==0) {//                val=min(val,a[i]);//                break;//            }//        }//        int pos=upper_bound(a,a+tp+1,val)-a;//        --pos;//        pos=min(pos,tp);        printf("%d\n",++tp);    }#ifdef tangge    GT(tEND);    printf("%.8lf\n",(tEND-tSTART)/1000.0);#endif // tangge    return 0;}
0 0