Hdu 5750 Dertouzos 素数筛 解题报告
2017-10-18 16:10
411 查看
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
910 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
100 13
Sample Output
12
1
0
0
0
0
0
4
思路
这道题先打表打一个素数筛,然后在主函数里面特判。代码
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<cmath> #include<vector> using namespace std; const int N=100000+5; int T,n,m,isprime ,primelist ,top=1; void prime() { for (int i=2;i<=N;i++) { if (isprime[i]==0) { for (int j=2;j*i<=N;j++) isprime[i*j]=1; primelist[top]=i; top++; } } } int main() { scanf("%d",&T); prime(); while(T--) { int i; scanf("%d%d",&m,&n); for (i=1;i<=top;i++) { if (n*primelist[i]>=m) break; if (n<primelist[i]) break; if (n%primelist[i]==0) break; } if (n*primelist[i]>=m||n<primelist[i]) i--; printf("%d\n",i); } return 0; }
相关文章推荐
- hdu 5750 Dertouzos (素数+数学)
- (解题报告)HDU2012---素数判定
- HDU2136解题报告(筛选法求素数)
- hdu 5750 Dertouzos 素数
- hdu2012——素数判定解题报告
- 解题报告:HDU_3988 Harry Potter and the Hide Story 大素数分解+勒让德
- HDU 2012 素数判定 解题报告
- HDU 5750 Dertouzos
- HDU 2544 SPFA(SLF) 解题报告
- hdu 1548 A strange lift bfs搜索 解题报告
- hdu 1384 Intervals 差分约束 解题报告
- HDU 1576 A/B 解题报告
- 杭电acm2091 hdu-acm-2091空心三角形解题报告
- BestCoder7 1001 Little Pony and Permutation(hdu 4985) 解题报告
- hdu 1272 解题报告
- HDU 2276解题报告
- hdu 1556 Color the ball 区间修改查询 解题报告
- HDU 1512 可并堆(左偏树) 解题报告
- HDU 4135解题报告
- HDU 1098解题报告