[暑假集训--数论]hdu2136 Largest prime factor
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.
InputEach line will contain one integer n(0 < n < 1000000).
OutputOutput the LPF(n).
Sample Input
1
2
3
4
5
Sample Output
0
1
2
1
3
对x分解质因数,问最大的质因子是第几大质数
瞎暴力就好
#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int mk[];
int pp[],len;
int rnk[];
int n;
inline void getp()
{
for (int i=;i<=;i++)
{
if (!mk[i])
{
for (int j=*i;j<=;j+=i)mk[j]=;
pp[++len]=i;
rnk[i]=len;
}
}
}
int main()
{
getp();
while (~scanf("%d",&n))
{
if (!mk[n]){printf("%d\n",rnk[n]);continue;}
int mx=;
for (int i=;i<=len;i++)
{
if (pp[i]*pp[i]>n)break;
if (n%pp[i]==)mx=i;
while (n%pp[i]==)n/=pp[i];
}
if (n!=)mx=rnk[n];
printf("%d\n",mx);
}
}
hdu 2136
[暑假集训--数论]hdu2136 Largest prime factor的更多相关文章
- 数学--数论--HDU2136 Largest prime factor 线性筛法变形
Problem Description Everybody knows any number can be combined by the prime number. Now, your task i ...
- [HDU2136] Largest prime factor(素数筛)
传送门 题意 给出若干个数n(n<=1000000),求每个n的最大质因子的排名. 质数的排名:如果素数p是第k小的素数,那么p的排名就是k. 思路 乍一看不知道怎么搞. 其实可以想想我们怎么筛 ...
- 【沙茶了+筛选保存最大质因数】【HDU2136】Largest prime factor
Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- The largest prime factor(最大质因数)
1. 问题: The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number ...
- HDOJ(HDU) 2136 Largest prime factor(素数筛选)
Problem Description Everybody knows any number can be combined by the prime number. Now, your task i ...
- (Problem 3)Largest prime factor
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 60085 ...
- 2136 Largest prime factor(打表)
Problem Description Everybody knows any number can be combined by the prime number.Now, your task is ...
- Largest prime factor
problem 3:Largest prime factor 题意:求600851475143的最大的质因数 代码如下: #ifndef PRO3_H_INCLUDED #define PRO3_H_ ...
- Problem 3: Largest prime factor
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 60085 ...
随机推荐
- Activiti学习记录(一)
1.工作流的概念 工作流(Workflow),就是“业务过程的部分或整体在计算机应用环境下的自动化”,它主要解决的是“使在多个参与者之间按照某种预定义的规则传递文档.信息或任务的过程自动进行,从而实现 ...
- VM内存溢出
平常开发时,有的人会运行的同时,会改代码,可能会导致VM内存溢出 Eclipse需要设置如下步骤: 1.点击Run>Run Configurations.. 2.定位到Tomcat(自己本地配置 ...
- java的重写(Override) (2013-10-11-163 写的日志迁移
/* *说明方法的重写(又称方法的覆盖)子类并不想原封不动地继承父类的方法,而是想作一定的修改 */ package czbk.jxy.study; /** * @author Archon * @d ...
- MTCNN学习资源
MTCNN pytorch版本的实现 TropComplique/mtcnn-pytorch https://github.com/TropComplique/mtcnn-pytorch MTCNN实 ...
- python列表中的赋值与深浅拷贝
首先创建一个列表 a=[[1,2,3],4,5,6] 一.赋值 a=[[1,2,3],4,5,6]b=aa[0][1]='tom'print(a)print(b)结果: [[1, 'tom', 3], ...
- 虚拟机中配置SQL SERVER2008R2远程访问
VM虚拟机中配置数据库访问 选择虚拟机设置--硬件--网络适配器,选择桥接模式:直接连接物理网络 不可选用主机模式(与主机共享专用网络) 数据库远程配置,转自:http://jingyan.baidu ...
- 指向class的指针使用方法实例
// pointer to classes example #include <iostream> using namespace std; class Rectangle { int w ...
- [BZOJ1588]营业额统计(Splay)
Description 题意:给定 n个数,每给定一个数,在之前的数里找一个与当前数相差最小的数,求相差之和(第一个数为它本身) 如:5 1 2 5 4 6 Ans=5+|1-5|+|2-1|+|5- ...
- P1605迷宫
题目背景 迷宫 [问题描述] 给定一个N*M方格的迷宫,迷宫里有T处障碍,障碍处不可通过.给定起点坐标和 终点坐标,问: 每个方格最多经过1次,有多少种从起点坐标到终点坐标的方案.在迷宫 中移动有上下 ...
- (Winform)控件中添加GIF图片以及运用双缓冲使其不闪烁以及背景是gif时使控件(如panel)变透明
Image img = Image.FromFile(@"C:\Users\joeymary\Desktop\3.gif"); pictureBox1.Image =img.Clo ...