hdu 5750 Dertouzos(数论)
2017-03-22 16:22
316 查看
Dertouzos
Problem DescriptionA 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
Source
BestCoder Round #84
题意:给定两个数n和d,问在[1,n)之间总共有多少个数的最大因子为d
分析:要使数x的最大因子为d,很容易想到这个数x=k*d,k为素数并且k<d,x<n
但是当k和d有公共的因子(不含1)或者k大于d的最小素因子时,那么这时最大的因子就不一定是d了,
比如说当n=150 d=22时 ,这时只有44符合条件,我么可以看到22的素因子为2和11,如果令k=5的话,那么x=110,但是它的最大因子为(5*11=)55,并不符合条件
所以k必须要小于等于d的最小素因子
思路:通过枚举素数,找出在[1,n)之间有多少个素数满足条件,即为结果
代码:
#include<stdio.h> #define maxn 1000000+10 int p[maxn/10],c[maxn]; void is_Prim() { int tot=0,i,j; c[0]=1,c[1]=1; for(i=2;i<=maxn;i++) { if(!c[i]) p[tot++]=i; for(j=0;j<tot&&i*p[j]<maxn;j++) { c[i*p[j]]=1; if(!(i%p[j])) break; } } } int main() { int t; is_Prim(); scanf("%d",&t); while(t--) { int n,m,i; scanf("%d%d",&n,&m); for(i=0;;i++) { if(p[i]*m>=n) break; if(m%p[i]==0) { i++; break; } } printf("%d\n",i); } return 0; }
相关文章推荐
- hdu 5750 Dertouzos(数论)
- hdu 5750 Dertouzos(数论)
- hdu 5750 Dertouzos(数论)
- HDU 5750 Dertouzos(数论)
- hdu 5750 Dertouzos(数论)
- hdu 5750 Dertouzos(数论)
- hdu 5750 Dertouzos(数论)
- hdu 5750 Dertouzos(数论)
- hdu 5750 Dertouzos(数论)
- BestCoder Round #84 &&HDU 5750 Dertouzos 【数论+暴力】
- hdu 5750 Dertouzos(数论)
- hdu 5750 Dertouzos(数论)
- HDU 5750 Dertouzos(数论)
- hdu 5750 Dertouzos(数论)
- HDU 5750 Dertouzos (数论)
- hdu 5750 Dertouzos(数论:质数枚举)
- hdu 5750 Dertouzos(数论)
- hdu-5750 Dertouzos(数论)
- hdu 5750 Dertouzos(数论,打表,暴力)
- hdu 5750 Dertouzos(数论)