HDU5750 Dertouzos
来源:互联网 发布:网络知识产权专利申请 编辑:程序博客网 时间:2024/05/15 17:17
Dertouzos
Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2054 Accepted Submission(s): 620
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 integersn and d . He would like to know the number of integers below n whose maximum positive proper divisor is d .
Peter has two positive integers
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 integersn and d (2≤n,d≤109) .
The first line contains two integers
Output
For each test case, output an integer denoting the answer.
Sample Input
910 210 310 410 510 610 710 810 9100 13
Sample Output
121000004
Source
BestCoder Round #84
题解
题解:给你 t 个 n 和 d ,让你求小于n的数中最大约数(不包括本身)为d的数量。
因为要使最大因数为d,必存在x*d=m,同时x必须为质数,且x必须小于d的最小质因数,因此找n前面有几个m成立即可。因为 t 范围很大,所以可以先打表筛选出质数表再线性扫一遍就可以了。
之前一直超时,后来才明白判断素数时超时
错误代码
#include<iostream>#include<string.h>#include<queue>#include<string>#include<stdio.h>#include<math.h>using namespace std;const int MAXN=1000010;int prime[MAXN+1];int getPrime(int m){ memset(prime,0,sizeof(prime)); for(int i=2;i<=m;i++) { if(!prime[i]) prime[++prime[0]]=i; for(int j=1;j<=prime[0]&&prime[j]<=m/i;j++) { prime[prime[j]*i]=1; if(i%prime[j]==0) break; } }}int main(){ int t; scanf("%d",&t); while(t--) { int n,m,ans; scanf("%d%d",&n,&m); ans=n/m; if(ans>m) { getPrime(m); printf("%d\n",prime[0]); } else { getPrime(ans); printf("%d\n",prime[0]); } } return 0;}AC代码
#include <iostream>#include<stdio.h>#include<algorithm>#include<string.h>#include<math.h>using namespace std;int isprime[100005]={0};int prime[10005]={0};int k=0;int init(){ int i,j; for(i=2;i<100000;i++) { if(isprime[i]==0) { for(j=2;i*j<100000;j++) { isprime[i*j]=1; } prime[k]=i;//存放素数的表, //这k表示i(包括i)前面有几个素数 k++; } } return 0;}int main(){ int t,i; int n,m; scanf("%d",&t); init(); while(t--) { scanf("%d%d",&n,&m); for(i=0;i<k;i++) { if(m*prime[i]>=n) break; if(m<prime[i]) break; if(m%prime[i]==0)//想想为什么 break; } if(m*prime[i]>=n||m<prime[i]) i--; printf("%d\n",i+1); }}
0 0
- HDU5750 Dertouzos
- HDU5750 Dertouzos(数论)
- hdu5750 Dertouzos (思路题)
- Dertouzos
- 【HDU5750 BestCoder Round 84D】【数学 贪心 复杂度计算】Dertouzos 范围有多少数的最大真约数为d
- HDU5750 (暴力+剪枝)
- HDU5750(数论,素数筛法)
- BestCoder Round #84 Dertouzos
- HDU 5750 Dertouzos
- hdu 5750 Dertouzos
- HDU-5750 Dertouzos
- HDOJ 5750 Dertouzos
- HDU 5750 Dertouzos
- HDU 5750 Dertouzos
- Hdu 5750 Dertouzos
- HDU 5750 Dertouzos
- HDU 5750 Dertouzos
- HDU 5750 Dertouzos(数论)
- 【BOI2007】逃跑问题 最小割
- 各种排序算法的实现——Java
- Tomcat安装目录下每个文件夹的功能
- 浅谈Web网站架构演变过程
- 详解Unity中的委托与事件
- HDU5750 Dertouzos
- 关于List 的小例子
- C语言好难——强制地址跳转
- 找工作经历(2017-03-22)
- bzoj2323[ZJOI2011]细胞 **
- python输出时间
- Chris and Magic Square
- 三层架构
- python读取csv文件并把文件放入一个list中脚本实例