【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 ...
随机推荐
- Java中 @override 报错
报错问题: 在我们导入别人的项目的时候有可能会出现Java类报错,点击错误时提示让我们remove掉@override.这是JDK版本的问题导致的跟源码无关. 解决方法: 方案1.直接删除掉报错的@o ...
- asp.net mvc 中使用NPOI导出excel
版本信息:NPOI1.2.5(2.0以上的版本很多方法不清楚) 明确三点: path: mvc 部署网站的时候,我们肯定要拷贝的一个文件夹就mvc的UI层,有点可以肯定的是,你部署网站的路径不一定都是 ...
- 2018CCPC 中国大学生程序设计竞赛 网络赛
链接 1.括号序列贪心/CF&51nod原题 [分析]: 贪心,每次到i的时候,假如你要在i里面要卖掉股票,获益是a[i], 肯定要在前面要么:1)把已经卖了的变成不买不卖,需要-a[j], ...
- CodeForces 738D Sea Battle
抽屉原理. 先统计最多有$sum$个船可以放,假设打了$sum-a$枪都没打中$a$个船中的任意一个,那么再打$1$枪必中. #pragma comment(linker, "/STACK: ...
- 洛谷P1197 [JSOI2008] 星球大战 [并查集]
题目传送门 星球大战 题目描述 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治者整个星系. 某一天,凭着一个偶然的机遇,一支反抗军摧毁了帝国的超级武器,并攻下了星系中几乎所有的星球.这 ...
- HZAU 1199 Little Red Riding Hood(DP)
Little Red Riding Hood Time Limit: 1 Sec Memory Limit: 1280 MBSubmit: 853 Solved: 129[Submit][Stat ...
- [BZOJ4765]普通计算姬(分块+树状数组)
4765: 普通计算姬 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 1725 Solved: 376[Submit][Status][Discus ...
- hdu 5963 朋友(2016ccpc 合肥站 C题)
朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submissi ...
- 【Tarjan】【LCA】【动态规划】【推导】hdu6065 RXD, tree and sequence
划分出来的每个区间的答案,其实就是连续两个的lca的最小值. 即5 2 3 4 这个区间的答案是min(dep(lca(5,2)),dep(lca(2,3),dep(lca(3,4)))). 于是dp ...
- 【2-SAT(tarjan)】BZOJ1997-[Hnoi2010]Planar
[题目大意]给出一张存在哈密顿回路的无向图,判断是否是平面图.[思路]首先平面图的一个性质:边数<=点数*3-6因为存在哈密顿回路,可以将回路看作是一个圆,考量不再哈密顿回路中的边.如果两天边相 ...