HDU 2136 Largest prime factor (素数打表。。。)
题意:给你一个数,让你求它的最大因子在素数表的位置。
析:看起来挺简单的题,可是我却WA了一晚上,后来终于明白了,这个第一层循环不是到平方根,
这个题和判断素数不一样,只要明白了这一点,就很简单了。
代码如下:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
#include <map>
#include <cctype>
#include <cmath> using namespace std;
typedef long long LL;
const int maxn = 1000000 + 5;
int a[maxn]; void init(){
memset(a, 0, sizeof(a));
int cnt = 1;
for(int i = 2; i < maxn; ++i) if(!a[i]){//这个地方不是sqrt(maxn+0.5)
a[i] = cnt++;
for(int j = i + i; j < maxn; j += i)
a[j] = a[i];//这个是不断更新的。
}
} int main(){
init();
int n;
while(~scanf("%d", &n))
printf("%d\n", a[n]);
return 0;
}
HDU 2136 Largest prime factor (素数打表。。。)的更多相关文章
- HDOJ(HDU) 2136 Largest prime factor(素数筛选)
Problem Description Everybody knows any number can be combined by the prime number. Now, your task i ...
- 2136 Largest prime factor(打表)
Problem Description Everybody knows any number can be combined by the prime number.Now, your task is ...
- HDU 2136 Largest prime factor(查找素数,筛选法)
题目梗概:求1000000以内任意数的最大质因数是第几个素数,其中 定义 1为第0个,2为第1个,以此类推. #include<string.h> #include<stdio.h& ...
- HDU 2136 Largest prime factor 參考代码
#include <iostream> #include <vector> #include <cmath> using namespace std; const ...
- HDU 2136 Largest prime factor
题目大意:求出比给出数小的互质的质数个数. 题解:直接用筛法求素数,稍微改编一下,将原先的布尔数组变为数组用来记录信息就可以了. 注意点:大的数组定义要放在程序的开头,不要放在main里面,不然会栈溢 ...
- 杭电 2136 Largest prime factor(最大素数因子的位置)
Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 【沙茶了+筛选保存最大质因数】【HDU2136】Largest prime factor
Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 【ACM】Largest prime factor
/*打表把素数能组合的数先设置成相应的位数*/ /* if n equals two and n is No.1 position of prime factors so four position ...
- [暑假集训--数论]hdu2136 Largest prime factor
Everybody knows any number can be combined by the prime number. Now, your task is telling me what po ...
随机推荐
- SpringBoot 常用注解(持续更新)
SpringBoot 常用注解 @SpringBootApplication @Bean @ComponentScan @ControllerAdvice @ExceptionHandler @Res ...
- UI5-文档-2.5-开发混合Web容器
开发混合Web容器 您可以将移动应用程序开发为混合应用程序,该混合应用程序由本机应用程序包装程序(例如PhoneGap)和HTML查看器组成,用于在用户界面上显示内容. 混合应用程序的优点是可以在应用 ...
- margin和padding的四种写法
我们经常会看到CSS样式属性中外边距margin和内边距padding的各种用法,这里做一个小结,但只简单介绍margin,因为它们的用法大同小异. 方法一. margin:10px; //4个外边距 ...
- hibernate自带的注解和jpa注解的冠希
hibernate是实现了JPA规范,在我们使用hibernate框架的时候,我们引入了hibernate3或者4这个核心包.hibernate-jpa-2.0-api-1.0.0.Final.jar ...
- jsp页面转发获取不到参数
使用的是<input type="hidden" name="nameid" value="${nameid}"/>,隐藏默认值 ...
- Plants vs. Zombies(二分好题+思维)
Plants vs. Zombies http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5819 BaoBao and DreamG ...
- Intersection(Check)
Intersection http://poj.org/problem?id=1410 Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- Asp.net实现同页面内多图片自动上传并带预览显示
FileUpload控件实现单按钮图片自动上传并带预览显示 1.实现原理: 此方法适合针对有后台生成的图片相关内容,例如购物网站商品展示页面中的封面图片,图片的数量由后台访问数据库,并加载到页面.这种 ...
- python2.7中可以使用到的一些模块地址
1.reportlab:由很多部分组成且允许用户使用多种方法创建输出,地址: 下载ReportLab https://pypi.python.org/simple/reportlab/ http:// ...
- 修改UITextView光标高度
自定义UITextView文字字体时,经常出现光标与字体的高度不匹配,可以通过下面代码修改默认的光标高度, //创建子类重写UITextView方法 - (CGRect)caretRectForPos ...