hdu 5750(数论)
2016-07-24 11:01
204 查看
Dertouzos
Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 891 Accepted Submission(s): 274
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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).
[align=left]Output[/align]
For each test case, output an integer denoting the answer.
[align=left]Sample Input[/align]
9
10 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
100 13
[align=left]Sample Output[/align]
1
2
1
0
0
0
0
0
4
题意:如果 d 是k除了自身以外最大的因子, 在[2,n)内找有多少个数满足 最大的因子是 k .
题解:昨天想得太简单了,真是naive..我开始的想法是 将 min(d,(n-1)/d) 里面所有的质数算出来,然后天真的以为这就是结果...然后一直WA,忽视了一个很重要的条件,那就是我们的数中d一定是最大的因子,所以如果出现了能够将d整除的质数,那么我们就可以将d分解,从而得到一个更大的 d' ,所以说我们选择的质数是不能够将 d 除尽的.
#include<iostream> #include<cstdio> #include<cstring> #include <algorithm> #include <math.h> using namespace std; typedef long long LL; const int N = 100005; bool p ; int prime ; int id; void init() { id = 0; for(int i=2; i<N; i++) { if(!p[i]) { prime[++id] = i; for(LL j=(LL)i*i; j<N; j+=i) { p[j] = true; } } } } int main() { init(); int tcase; scanf("%d",&tcase); while(tcase--) { int n,d; scanf("%d%d",&n,&d); int ans = 0; for(int i=1; i<=id; i++) { if(prime[i]*d>=n) break; ans++; if(d%prime[i]==0) break; } printf("%d\n",ans); } return 0; }
相关文章推荐
- Java 技术新手入门
- Java 专业人士必备的书籍和网站列表
- 数论 2017.1.14
- 找数组中唯一重复的元素
- 漫谈Linux内核哈希表(2)
- 漫谈Linux内核哈希表(1)
- 刨一刨内核container_of()的设计精髓
- Linux内核【链表】整理笔记(2)
- Linux内核【链表】整理笔记(1)
- Linux 内核通知链随笔【中】
- 关于openssl几个API的一点小收获
- 经典排序算法归纳笔记(4)
- 经典排序算法归纳笔记(2)
- 经典排序算法归纳笔记(1)
- 从新版本系统调用学习宏定义的用法
- 多媒体技术基础之---色彩空间
- 多媒体技术基础之---图像
- "2013":爱你不容易
- 谈谈Linux下动态库查找路径的问题
- CentOS6.4完全安装FFmpeg手记