思路题 素因子 HDU 5750
来源:互联网 发布:网络安全法的基本特性 编辑:程序博客网 时间:2024/06/04 23:30
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5750
Dertouzos
Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2172 Accepted Submission(s): 672
Problem Description
A positive proper divisor is a positive divisor of a number n n, excluding n n itself. For example, 1, 2, and 3 are positive proper divisors of 6, but 6 itself is not.
Peter has two positive integersn n and d d. He would like to know the number of integers below n n whose maximum positive proper divisor is d d.
Peter has two positive integers
The first line contains two integers
910 210 310 410 510 610 710 810 9100 13
121000004
题意:为你一个n和一个d;在2到n中找出一些数,例如6,它有因子2,3(因子除了1和它本身,下同);所以6的最大因子是3,
现在在2到n中找出一些数,这些数的最大因子是d;求这些数有多少个;
思路:假设一个数为a,使得d*a<n;如果a不是素数的话,a总是有一个因子b,使得b*d>d,即a*d的因子b*d比因子d大,所以a*d一定不符合条件,如果a>d&&d*a<n,a*d也一定不符合条件,因为a比d大;如果a比d的其中一个因子大,就可以替换那个因子得到比d大的数字,所以当d%a==0;时说明比a大的素数一定不行,直接break;
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<map>#include<string>#define LL long long int#define inf 0x3f3f3f3f#define N 100010#define mod 10000007using namespace std;bool a[50100]={0};int b[10000];int main(){ int sum=0; for(int i=2;i<=50000;i++) { if(!a[i]) { for(int j=i*2;j<=50000;j+=i) a[j]=1; b[sum++]=i; } } int t; scanf("%d",&t); while(t--) { int n,d; int ans=0; scanf("%d%d",&n,&d); for(int i=0;b[i]*d<n&&b[i]<=d;i++) { ans++; if(d%b[i]==0) break; } printf("%d\n",ans); }}
0 0
- 思路题 素因子 HDU 5750
- HDU 5750 Dertouzos(思路题)
- 比较两种不同思路分解素因子
- 浙大PAT 2-07. 素因子分解 (解题思路)
- HDU 4970 思路题
- HDU 5301 思路题
- HDU 5317 RGCDQ (素因子分解+预处理)
- hdu 5108 求最大素因子
- HDU 2710 求最大素因子
- [思路题] hdu 5124 lines
- HDU 5705(思路题)
- HDU 5821 Ball 思路题
- hdu 1215因子和
- hdu 4961 因子
- HDU 5428 【水+因子。。?】
- hdu 4432 因子
- HDU 1215 因子相加
- HDU 1695(数论,筛选+素因子分解+容斥)
- oracle远端的导出,导入
- 476. Number Complement(C语言)
- maven拉包问题
- 二级指针做输入第1种模型
- React Native在windows上android环境搭配及注意事项
- 思路题 素因子 HDU 5750
- 真·天气API接口,图片API接口,音乐API接口
- 视差特效(仿微信朋友圈)
- Maven私服Nexus3.x环境构建操作记录
- opencv SVD算法
- 面向接口编程的优点
- 反射_获取class文件对象的三种方式
- gcc-6.3.0 构建
- mybatis接口式编程