【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 ...
随机推荐
- 五十一 常用第三方模块virtualenv
在开发Python应用程序的时候,系统安装的Python3只有一个版本:3.4.所有第三方的包都会被pip安装到Python3的site-packages目录下. 如果我们要同时开发多个应用程序,那这 ...
- windows 安装tp5 composer方式
1.下载windows composer-setup.exe(我已下载一个Composer-Setup.exe); 2.我电脑使用的是phpstudy2018版 php-7.0.12-NTS 3.然后 ...
- PTA L1-020 帅到没朋友 团体程序设计天梯赛-练习集
L1-020 帅到没朋友(20 分) 当芸芸众生忙着在朋友圈中发照片的时候,总有一些人因为太帅而没有朋友.本题就要求你找出那些帅到没有朋友的人. 输入格式: 输入第一行给出一个正整数N(≤),是已 ...
- web服务器解析漏洞总结(转)
转:http://www.secpulse.com/archives/3750.html 解析漏洞总结 2015 /1/27 22:09 一.IIS 5.x/6.0解析漏洞 IIS 6.0解析利用方法 ...
- HDU 5552 Bus Routes(2015合肥现场赛A,计数,分治NTT)
题意 给定n个点,任意两点之间可以不连边也可以连边.如果连边的话可以染上m种颜色. 求最后形成的图,是一个带环连通图的方案数. 首先答案是n个点的图减去n个点能形成的树. n个点能形成的树的方案数比 ...
- 使用html+css实现三角标示符号
我们平常打开某个网站的时候,常常会发现网页上很多导航或者指示条会使用一个三角符号去指向内容,效果简洁美观,甚至很多前端面试中也会提及如何在网页上实现一个三角符号,这里给出一个很简单使用的实现方式. 首 ...
- asp总结
什么是ASP.NET? ASP.NET是.NET FrameWork的一部分,是一项微软公司的技术,是一种使嵌入网页中的脚本可由因特网服务器执行的服务器端脚本技术,它可以在通过HTTP请求文档时再在W ...
- 【CCpp程序设计2017】简单进销存
题目:简单进销存 功能要求: 实现如下的菜单(按数字选择菜单功能): 1. 显示存货列表 2. 入库 3. 出库 4. 退出程序 实现菜单对应功能(需记录货物的型号.数量等信息): 程序启动时从文件中 ...
- 【线段树/区间开平方】BZOJ3211-花神游历各国
[题目大意] 给出一些数,有两种操作.(1)将区间内每一个数开方(2)查询每一段区间的和 [思路] 普通的线段树保留修改+开方优化.可以知道当一个数为0或1时,无论开方几次,答案仍然相同.所以设置fl ...
- UNIX域套接字连接mysql
用户可以在配置文件中指定套接字文件的路径,如--socket=/data/mysql/mysql.sock [root@localhost ~]# mysql -uroot -p123456 -S / ...