【ACM】Largest prime factor

/*打表把素数能组合的数先设置成相应的位数*/
/* if n equals two and n is No.1 position of prime factors so four position of prime factors is no.1,as well*/
/* although two can combined six but three also can combined six */
/* and three position of prime factors is two ,two covered one then six largest prime factor */
/*position is two now, have fun ;-) */
#include <stdio.h>
#include <stdlib.h>
#define MAX 1000000
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int *lpf = malloc( MAX*sizeof(int) ); /*if use "int lpf[MAX]" could be overflow*/
int n , num ;
int i , j ;
num = 0 ;
lpf[1] = 0 ;
for( i = 2 ; i < MAX ; i++ ) {
if( 0 == lpf[i] ){
num++ ;
for( j = i ; j < MAX ; j=j+i )
lpf[j] = num ;
} }
while( scanf("%d",&n) != EOF )
printf("%d\n",lpf[n]);
return 0;
}
【ACM】Largest prime factor的更多相关文章
- 【沙茶了+筛选保存最大质因数】【HDU2136】Largest prime factor
Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”
按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...
- 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 ...
- R语言学习——欧拉计划(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 ...
随机推荐
- Chrome浏览器你可以选择知道的知识
Chrome浏览器我想是每一个前端er必用工具之一吧,一部分原因是它速度快,体积不大,支持的新特性也比其它浏览器多,还有一部分我想就是因为它的控制台功能强大了吧,说它是神器一点也不过分,很方便.但其实 ...
- react native项目增加devtools工具
第一步:安装react devtools工具 在当前项目中打开命令行,添加react devtools工具,因为运行的工具有九十几M,下载时需要时间,请耐心等待 yarn add react-devt ...
- Nodejs Mocha测试学习
参考大神阮一峰的文章<测试框架 Mocha 实例教程> 目前在使用Nodejs,但写完的程序很容易出错,那怎么办?需要引入单元测试去做基础的测试 目前Nodejs用来做单元测试的工具接触的 ...
- 洛谷P4331 [BOI2004] Sequence 数字序列 [左偏树]
题目传送门 数字序列 题目描述 给定一个整数序列 a1,a2,⋅⋅⋅,an ,求出一个递增序列 b1<b2<⋅⋅⋅<bn ,使得序列 ai 和 bi 的各项之差的绝对 ...
- coreseek mmseg分词配置和创建
1.文件格式为 沃尔沃 1x:1现代 1x:1徐工 1x:1住友 1 ... 3.将生成的符合格式要求的词表粘贴到原词表unigram.txt末尾,保存为unigram_new.txt,并拷贝到mms ...
- JZYZOJ1355 [usaco2007]奶牛赛跑 矩阵乘法 离散化
http://172.20.6.3/Problem_Show.asp?id=1355 写的时候本来想离散化,“1000^2的数组放一两个到函数里而已嘛,指定承受得住”,然后没离散化,然后就爆栈了, ...
- [Codeforces-div.1 494B]Obsessive String
[CF-div.1 B]Obsessive String 题目大意 两个字符串\(S,T\),求划分方案数使得一个集合中两两划分不相交且划分都包含字符串\(T\) 试题分析 kmp先求出那个位置匹配. ...
- 【FFT】OpenJ_POJ - C17H - Reverse K-th Problem
对每个位置i处理出以其为结尾,且比a(i)大的数有j个的前缀个数,记成一个数组l:同理,处理出以其为开头,且比a(i)大的数有j个的后缀的个数,记成一个数组r. 整个序列中比a(i)大的数的个数的数组 ...
- CDOJ 1280 772002画马尾 每周一题 div1 矩阵快速幂
772002画马尾 题目连接: http://acm.uestc.edu.cn/#/problem/show/1280 Description 众所周知772002很喜欢马尾,所以他决定画几幅马尾送给 ...
- tomcat配置优化
tomcat服务管理页面 http://192.168.1.249:8080/manager/status 找到下面的内容 "http-nio-8081" (此处端口是根据自己实 ...