Largest prime factor

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8976    Accepted Submission(s): 3191

Problem Description
Everybody knows any number can be combined by the prime number. Now, your task is telling me what position of the largest prime factor. The position of prime 2 is 1, prime 3 is 2, and prime 5 is 3, etc. Specially, LPF(1) = 0.
 
Input
Each line will contain one integer n(0 < n < 1000000).
 
Output
Output the LPF(n).
 
Sample Input
1
2
3
4
5
 
Sample Output
0
1
2
1
3
 
Author
Wiskey
 
Source
 
题意:求一个数的最大质数因子在素数表中的位置
 素数打表+求质因子
 
#include<bits/stdc++.h>
using namespace std;
int n;
bool visit[1000005];
int prime[1000005];
map<int,int>mp;
int len;
int que[10];
void init_prim()
{
memset(visit, true, sizeof(visit));
int num = 0;
for (int i = 2; i <= 1000000; ++i)
{
for(int j=i+i;j<=1000000;j=j+i)
visit[j]=false;
}
for(int i=2;i<=1000000;i++)
if(visit[i])
{
prime[++num]=i;
mp[i]=num;
}
}
void prime_(int nn)
{
len=0;
for(int i=2;i*i<=nn;i++)
{
if(nn%i==0)
{
que[len++]=i;
while(nn%i==0)
{
nn=nn/i;
}
}
}
if(nn>1)
que[len++]=nn;
}
int main()
{
init_prim();
while(scanf("%d",&n)!=EOF)
{
len=0;
memset(que,0,sizeof(que));
if(n==1)
printf("0\n");
else
{
prime_(n);
sort(que,que+len);
//cout<<len<<endl;
printf("%d\n",mp[que[len-1]]);
}
}
return 0;
}
 

HDU 2136 素数打表+求质数因子的更多相关文章

  1. uva11610 树状数组+素数打表求因子,好题!

    /* uva11610 树状数组+素数打表+离散化 打出的素数范围在2-1000000之间,不超过六位数,然后按照格式翻转成七位数 */ #include<bits/stdc++.h> u ...

  2. hdu 5104 素数打表水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5104 找元组数量,满足p1<=p2<=p3且p1+p2+p3=n且都是素数 不用素数打表都能过,数据 ...

  3. HDU 3792 素数打表

    Description If we define dn as: dn = pn+1-pn, where pi is the i-th prime. It is easy to see that d1 ...

  4. poj 2992 Divisors (素数打表+阶乘因子求解)

    Divisors Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9617   Accepted: 2821 Descript ...

  5. HDOJ(HDU) 2136 Largest prime factor(素数筛选)

    Problem Description Everybody knows any number can be combined by the prime number. Now, your task i ...

  6. 埃氏筛法求素数&构造素数表求素数

    埃氏筛法求素数和构造素数表求素数是一个道理. 首先,列出从2开始的所有自然数,构造一个序列: 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1 ...

  7. 算法笔记(c++)--求一个数的所有质数因子

    算法笔记(c++)--求一个数的所有质数因子 先贴题目: 这题不难,恶心在理解上面.最后看评论知道了怎么回事: 2*2*3*3*5=180 按照这逻辑的话应该输入的数由一系列质数相乘出来,所以每次找到 ...

  8. php实现求一个数的质数因子

    php实现求一个数的质数因子 一.总结 一句话总结:这么简单的题目,还是把变量定义的位置和自增的位置写错. 1 <?php 2 $num=trim(fgets(STDIN)); 3 //如果$n ...

  9. HDU 1397 Goldbach's Conjecture【素数打表】

    题意:给出n,问满足a+b=n且a,b都为素数的有多少对 将素数打表,再枚举 #include<iostream> #include<cstdio> #include<c ...

随机推荐

  1. [知识库:python-tornado]异步调用中的上下文控制Tornado stack context

    异步调用中的上下文控制Tornado stack context https://www.zouyesheng.com/context-in-async-env.html 这篇文章真心不错, 非常透彻 ...

  2. SpringBoot项目打包成jar后,启动脚本

    将springboot项目打包成jar后,上传至服务器,每次都需要手敲命令,重新部署项目,可将这些命令写入脚本中,直接运行. 启动脚本(start.sh): CUR_PATH=$(cd "$ ...

  3. 【python】scrapy相关

    目前scrapy还不支持python3,python2.7与python3.5共存时安装scrapy后,执行scrapy后报错 Traceback (most recent call last): F ...

  4. 手机站测试工具(node服务器)

    最近在工作中遇到手机站测试的问题,于是就写了一个node服务外加一个第三方的转二维码功能,欢迎拍砖~ 项目地址:https://github.com/finderL/webserver

  5. wpa_supplicant上行接口浅析

    摘自http://blog.csdn.net/fxfzz/article/details/6176414 wpa_supplicant提供的接口 从通信层次上划分, 上行接口:wpa_supplica ...

  6. JavaScript中childNodes和children的区别

    我在学习JavaScript对DOM操作的过程中,发现了使用childNodes属性,得不到我想要的结果,因此我就从JavaScript高级程序设计中了解了childNodes和children的区别 ...

  7. 内部网关协议RIP 路由选择算法(距离向量)

    RIP是一种基于距离向量的路由选择协议 RIP的距离就是指的跳数,没经过一个路由,就是一跳,RIP允许一跳路径最多经过15个路由器,所以16个的话就相当于不可以到达了 RIP协议的特点: 1:仅和相邻 ...

  8. 一个demo让你彻底理解Android中触摸事件的分发

    注:本文涉及的demo的地址:https://github.com/absfree/TouchDispatch 1. 触摸动作及事件序列 (1)触摸事件的动作 触摸动作一共有三种:ACTION_DOW ...

  9. lintcode-197-排列序号

    197-排列序号 给出一个不含重复数字的排列,求这些数字的所有排列按字典序排序后该排列的编号.其中,编号从1开始. 样例 例如,排列 [1,2,4] 是第 1 个排列. 思路 参考http://www ...

  10. iOS-加载html字符串

    NSMutableAttributedString * attrString =[[NSMutableAttributedString alloc] initWithData:[resultModel ...