HD-ACM算法专攻系列(18)——Largest prime factor
题目描述:

源码:
需要注意,若使用cin,cout输入输出,会超时。
#include"iostream"
#include"memory.h"
#define MAX 1000000
using namespace std; int index[MAX]; int main()
{ memset(index, -1, sizeof(index));
index[1] = 0;
int sum = 0;
for(int i = 2; i < MAX; i++)
{
if(index[i] == -1)
{
sum++;
for(int j = i; j < MAX; j+= i)
index[j]=sum;
}
} int n;
while(scanf("%d", &n) != EOF)
printf("%d\n", index[n]);
return 0;
}
HD-ACM算法专攻系列(18)——Largest prime factor的更多相关文章
- 【ACM】Largest prime factor
/*打表把素数能组合的数先设置成相应的位数*/ /* if n equals two and n is No.1 position of prime factors so four position ...
- 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 ...
- 【沙茶了+筛选保存最大质因数】【HDU2136】Largest prime factor
Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- (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 ...
- [暑假集训--数论]hdu2136 Largest prime factor
Everybody knows any number can be combined by the prime number. Now, your task is telling me what po ...
随机推荐
- 移动端布局 rem,和px
1.rem布局,根据屏幕来计算rem,也就是意义上的适应屏幕,但是一些字体大小转换和计算有些复杂. // rem 布局重定义 (function(){ $('html').css('font-size ...
- Brain Network (hard) CodeForces - 690C 简单倍增 + 一些有趣的推导
Code: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ...
- python与图灵机器人交互(ITCHAT版本)
#!/usr/bin/env python#-*- coding:utf-8 -*- @Author : wujf @Time:2018/9/5 17:42import requestsimport ...
- 【Git教程】Git教程及使用命令
Git是目前世界上最先进的分布式版本控制系统,可以自动记录和管理文件的改动,还可以团队写作编辑,也就是帮助我们对不同的版本进行控制.2008年,GitHub网站上线,为开源项目提供免费存储,迅速发 ...
- Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)C. Laboratory Work
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some v ...
- JS防抖与节流
在进行窗口的resize.scroll,输入框内容校验等操作时,如果事件处理函数调用的频率无限制,会加重浏览器的负担,导致用户体验非常糟糕.此时我们可以采用debounce(防抖)和throttle( ...
- Project Euler 14 Longest Collatz sequence
题意:对于任意一个数 N ,寻找在 100,0000 之内按照规则( N 为奇数 N = N * 3 + 1 ,N 为偶数 N = N / 2 ,直到 N = 1 时的步数 )步数的最大值 思路:记忆 ...
- 批量修改Linux系统密码
截取主机IP地址最后一位数.匹配一组定义好的自定义密码.使用chpasswd修改主机账户密码 截图主机IP [root@web01 ~]# ip addr 1: lo: <LOOPBACK,UP ...
- Problem 5
Problem 5 # Problem_5.py """ 2520 is the smallest number that can be divided by each ...
- 出现$ref的原因及解决方案
$ref的产生原因 (1)重复引用:一个集合/对象中的多个元素/属性都引用了同一个对象 (2)循环引用:集合/对象中的多个元素/属性在相互引用导致循环 针对fastjson的处理 fastjson作为 ...