hdu 5750 Dertouzos(数论)
来源:互联网 发布:企业淘宝怎么注册 编辑:程序博客网 时间:2024/05/18 02:01
Dertouzos
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
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+10int 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(数论,打表,暴力)
- BestCoder Round #84 &&HDU 5750 Dertouzos 【数论+暴力】
- hud 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
- B
- getSession(true/false)和getSession()的区别
- js Map 获取值
- 自定义控件之绘图篇(六) —— Path之贝赛尔曲线和手势轨迹、水波纹效果
- P1605 迷宫
- hdu 5750 Dertouzos(数论)
- js里查询对象和方法
- Jquery中的ajax在默认不写async情况下,请求为异步请求;即:async:true;
- HDU
- ubuntu14.04+cuda8.0+caffe
- 【OpenGL】nehe教程第一课学习笔记
- 人工智能知识库
- Git托管:将本地项目代码上传(push)到自己的Git repository
- C#与Kinect v1(2):图片保存与多线程处理