【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 ...
随机推荐
- HP自动检查html标签是否闭合
function HtmlClose($body) { $strlen_var = strlen($body); // 不包含 html 标签 if (strpos($body, '<') == ...
- LOJ #6284. 数列分块入门 8-分块(区间查询等于一个数c的元素,并将这个区间的所有元素改为c)
#6284. 数列分块入门 8 内存限制:256 MiB时间限制:500 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: hzwer 提交提交记录统计测试数据讨论 2 题目描述 给出 ...
- java过滤敏感词汇
前言 现在几乎所有的网站再发布带有文字信息的内容时都会要求过滤掉发动的.不健康的.影响社会安定的等敏感词汇,这里为大家提供了可以是现在这种功能的解决方案 第一种方式 创建敏感词汇文件:首先需要准备一个 ...
- Flask实战第43天:把图片验证码和短信验证码保存到memcached中
前面我们已经获取到图片验证码和短信验证码,但是我们还没有把它们保存起来.同样的,我们和之前的邮箱验证码一样,保存到memcached中 编辑commom.vews.py .. from utils i ...
- 【数据结构】 最小生成树(四)——利用kruskal算法搞定例题×3+变形+一道大水题
在这一专辑(最小生成树)中的上一期讲到了prim算法,但是prim算法比较难懂,为了避免看不懂,就先用kruskal算法写题吧,下面将会将三道例题,加一道变形,以及一道大水题,水到不用高级数据结构,建 ...
- Rxjava与Retrofit的使用
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha ---- -----
- Codeforces 551 D. GukiZ and Binary Operations
\(>Codeforces \space 551 D. GukiZ and Binary Operations<\) 题目大意 :给出 \(n, \ k\) 求有多少个长度为 \(n\) ...
- BZOJ 3997 [TJOI2015]组合数学(单调DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3997 [题目大意] 给出一个网格图,其中某些格子有财宝,每次从左上角出发,只能向下或右 ...
- 20162318 2016-2017-2《Java程序设计》课堂实践项目
20162318 2016-2017-2<Java程序设计>课堂实践项目 String类的使用 在String类中有一种split的方法.它可以把字符串分割为好几个小的字符串. 实践内容: ...
- Problem A: 插入一个数到数列中
#include<stdio.h> int main() { ]={,,,,,,,,},i,k; scanf("%d",&n); a[]=n; ;i<=; ...