HDU-#5108 Alexandra and Prime Numbers
2014-11-22 22:06
274 查看
题目大意:给一个数N,求一个最小的M,使得N/M是素数。
解题思路:好久没做比赛了,手已经生的不行了,自己被Hacker了不说,Hacker别人居然也被抢了,实在不应该....好久不做题就各种手残呀....本题就直接反过来求即可,要求最小的M,则要求N最大的素因子。对于利用数的素因子拆分原理求解即可,特别注意需要题目为0的情况是N为1时。
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=5108
code:
解题思路:好久没做比赛了,手已经生的不行了,自己被Hacker了不说,Hacker别人居然也被抢了,实在不应该....好久不做题就各种手残呀....本题就直接反过来求即可,要求最小的M,则要求N最大的素因子。对于利用数的素因子拆分原理求解即可,特别注意需要题目为0的情况是N为1时。
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=5108
code:
#include <iostream> #include <cstdio> #include <cstring> using namespace std; int n,ans; int main(){ while(~scanf("%d",&n)){ if(n==1) printf("0\n"); else{ int cnt=n; for(int i=2;i*i<=cnt;++i) while(cnt%i==0){ cnt/=i; ans=i; } if(cnt>1) ans=cnt; printf("%d\n",n/ans); } } return 0; }
相关文章推荐
- hdu 5108 Alexandra and Prime Numbers
- HDU 5108 Alexandra and Prime Numbers
- HDU 5108Alexandra and Prime Numbers(大素数)
- 【数论】hdu-5108-Alexandra and Prime Numbers(求最大质因数) (BestCoder Round #19)
- BestCoder19 1001.Alexandra and Prime Numbers(hdu 5108) 解题报告
- HDU-5108-Alexandra and Prime Numbers
- hdu 5108 Alexandra and Prime Numbers
- hdu5108——Alexandra and Prime Numbers(素数)
- hdu 5108 Alexandra and Prime Numbers (水题,暴力)
- hdu 5108——Alexandra and Prime Numbers
- HDU 5108 Alexandra and Prime Numbers
- hdu 5108 Alexandra and Prime Numbers(水题 / 数论)
- hdu 5108 Alexandra and Prime Numbers(素数)
- HDUOJAlexandra and Prime Numbers
- BestCoder Round #19 1001 Alexandra and Prime Numbers 11.96%(193/1614)
- Alexandra and Prime Numbers(思维)
- Java Program to print Prime numbers in Java - Example Tutorial and Code
- CF385C-(Bear and Prime Numbers)线性筛素数
- hdu acmsteps 2.1.2 How many prime numbers
- hdu 1905 Pseudoprime numbers