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 <stdio.h>
#include <math.h>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
#define N 1000000
int a[N];
void pd(){
int n=,i,t,j;
memset(a,,sizeof(a));
for(i=;i<=N;i++)//对当前数的每个数的倍数进行赋值素数编号 可以覆盖哦 因为要覆盖为最大因子
{
if(a[i]==)
{
n++;//素数i的位置
for(j=i;j<=N;j+=i)//构造出j的暂时最大素数因子的位置
a[j]=n;
}
}
}
int main()
{
int i;
pd();
while(~scanf("%d",&i))
{
printf("%d\n",a[i]);
}
return ;
}

2136 Largest prime factor(打表)的更多相关文章

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

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

  2. 杭电 2136 Largest prime factor(最大素数因子的位置)

    Largest prime factor Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  3. HDU 2136 Largest prime factor (素数打表。。。)

    题意:给你一个数,让你求它的最大因子在素数表的位置. 析:看起来挺简单的题,可是我却WA了一晚上,后来终于明白了,这个第一层循环不是到平方根, 这个题和判断素数不一样,只要明白了这一点,就很简单了. ...

  4. HDU 2136 Largest prime factor(查找素数,筛选法)

    题目梗概:求1000000以内任意数的最大质因数是第几个素数,其中 定义 1为第0个,2为第1个,以此类推. #include<string.h> #include<stdio.h& ...

  5. HDU 2136 Largest prime factor 參考代码

    #include <iostream> #include <vector> #include <cmath> using namespace std; const ...

  6. HDU 2136 Largest prime factor

    题目大意:求出比给出数小的互质的质数个数. 题解:直接用筛法求素数,稍微改编一下,将原先的布尔数组变为数组用来记录信息就可以了. 注意点:大的数组定义要放在程序的开头,不要放在main里面,不然会栈溢 ...

  7. 【沙茶了+筛选保存最大质因数】【HDU2136】Largest prime factor

    Largest prime factor Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  8. 【ACM】Largest prime factor

    /*打表把素数能组合的数先设置成相应的位数*/ /* if n equals two and n is No.1 position of prime factors  so four position ...

  9. [暑假集训--数论]hdu2136 Largest prime factor

    Everybody knows any number can be combined by the prime number. Now, your task is telling me what po ...

随机推荐

  1. uva 10245 近期点对问题

    分治法的典例 当练手了 奇妙的是.使用inplace_merge按说应该是O(n)的算法.可是用sort nlogn的算法反而更快 先上快排版 #include <cstdio> #inc ...

  2. 常用Android开源框架

    1.volley 项目地址 https://github.com/smanikandan14/Volley-demo  (1)  JSON,异步下载图片:  (2)  网络请求的排序(scheduli ...

  3. Apple Swift编程语言入门

    1   简单介绍 今天凌晨Apple刚刚公布了Swift编程语言,本文从其公布的书籍<The Swift Programming Language>中摘录和提取而成.希望对各位的iOS&a ...

  4. 未能加载文件或程序集“Common”或它的某一个依赖项。试图加载格式不正确的程序

    原因:操作系统是64位的,但发布的程序引用了一些32位的ddl,所以出现了兼容性的问题解决方案一:如果是64位机器,IIS——应用程序池——高级设置——启用32位应用程序 :true.解决方案二:修改 ...

  5. 【Shell剧本练习】得出的结论是当前用户

    推断是否当前用户root.假设是暗示root用户,假设而不是提示对于普通用户 #!/bin/bash #title: testus.sh #author: orangleliu #date: 2014 ...

  6. kettle 4.4源代码分析Transformation

    1.1. 相关的类和接口 1.1.1. JobEntryTrans 实现了JobEntryInterface的execute()方法,被job运行.由JobEntryTrans实例化Trans,并运行 ...

  7. C# - Dictionary join keys or join Values

    using System; using System.Collections.Generic; using System.Linq; using System.Text; public class P ...

  8. 简单实现Android平台多语言

    这里,我们认识到两种语言.中国简体和繁体中国. 在res文件建议两个文件夹 values-zh-rCN values-zh-rTW 两个目录下都有一个strings.xml文件. 两个同名文件的字符串 ...

  9. Codeforces Beta Round #3 A. Shortest path of the king

    标题效果: 鉴于国际棋盘两点,寻求同意的操作,是什么操作的最小数量,在操作过程中输出. 解题思路: 水题一个,见代码. 以下是代码: #include <set> #include < ...

  10. UVA 11464 Even Parity(递归枚举)

    11464 - Even Parity Time limit: 3.000 seconds We have a grid of size N x N. Each cell of the grid in ...