HDU5750(数论,素数筛法)
来源:互联网 发布:大数金科网络 编辑:程序博客网 时间:2024/05/29 13:32
Dertouzos
Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2125 Accepted Submission(s): 647
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
题解:题目大意:老规矩,去读读吧!
我的思路:先筛一遍素数,筛素数的时候只需要筛选到1e9开根号。至于为什么,因为他是要找小于n的切以d为最大因子的数。那么最多另外一个因子等于d,不可能大于d,因为大于d,d就不是最大因子了也就是d的平方小于n,所以素数筛出1e5就行了。然后从2到d的做小素因子跑一遍,素数的个数就最终的结果。这一点自己可以去思考一下。(为什么一定要是素数才满足题意? 还有就是为什么只需要遍历到d的最小素因子就行了?自己举个反例思考一下,对于搞算法的应该不难吧!)
下面附上代码:
#include<cstdio>#include<string>#include<cstring>#include<algorithm>#include<climits>#include<map>#include<iostream>#include<vector>#include<queue>#include<stack>#include<cmath>using namespace std;int a[100005];int main(){ for(int i = 2; i <= 1000; i++) { if(!a[i]) for(int j = i*2; j <= 100000; j+=i) { a[j] = 1; } } int T; scanf("%d", &T); while(T--) { int n, d, sum = 0; scanf("%d%d", &n, &d); for(int i = 2; i <= d; i++) { if(i*d >= n) break; if(!a[i]) sum++; if(!a[i] && d%i==0 && d!=i) break; } printf("%d\n", sum); }}
0 0
- HDU5750(数论,素数筛法)
- HDU5750 Dertouzos(数论)
- 数论专题小结:素数筛法
- luogu 1865 数论 线性素数筛法
- HDU 5317(数论,素数筛法)
- 数论——素数筛法
- 【数论】筛素数
- [数论] HDU 1431 素数回文 筛素数
- poj——2689(数论之素数筛法)
- 浅谈数论(二)进阶素数筛法
- 数论知识点2——素数筛法-HDOJ 2136
- Uva 10006 Carmichael Numbers(数论、快速幂、素数筛法)
- POJ 2689 Prime Distance [筛法选取素数]【数论】
- 数论之素数(质因数分解与筛法)
- 数论-素数
- [数论]HDU 1215 七夕节 筛素数
- [数论] HOJ 2276 Count prime 筛素数
- [数论] NEFU 2 猜想 筛素数
- 案例剖析:如何优化外贸网店提高支付率?
- cd目录下的几个命令
- hadoop
- gradle 压缩资源配置
- Oracle数据库的查询之子查询(六)
- HDU5750(数论,素数筛法)
- Appium-Android开发环境
- 被gank的openjudge2745
- 自定义View基础之坐标系
- redis集群搭建
- webpack新手简单入门1
- LeetCoder_____2Sum,3Sum,4Sum
- 四平方和
- android onKeyDown与输入法冲突问题解决方法