题意:给你一个数,让你求它的最大因子在素数表的位置。

析:看起来挺简单的题,可是我却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 (素数打表。。。)的更多相关文章

  1. HDOJ(HDU) 2136 Largest prime factor(素数筛选)

    Problem Description Everybody knows any number can be combined by the prime number. Now, your task i ...

  2. 2136 Largest prime factor(打表)

    Problem Description Everybody knows any number can be combined by the prime number.Now, your task is ...

  3. HDU 2136 Largest prime factor(查找素数,筛选法)

    题目梗概:求1000000以内任意数的最大质因数是第几个素数,其中 定义 1为第0个,2为第1个,以此类推. #include<string.h> #include<stdio.h& ...

  4. HDU 2136 Largest prime factor 參考代码

    #include <iostream> #include <vector> #include <cmath> using namespace std; const ...

  5. HDU 2136 Largest prime factor

    题目大意:求出比给出数小的互质的质数个数. 题解:直接用筛法求素数,稍微改编一下,将原先的布尔数组变为数组用来记录信息就可以了. 注意点:大的数组定义要放在程序的开头,不要放在main里面,不然会栈溢 ...

  6. 杭电 2136 Largest prime factor(最大素数因子的位置)

    Largest prime factor Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  7. 【沙茶了+筛选保存最大质因数】【HDU2136】Largest prime factor

    Largest prime factor Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  8. 【ACM】Largest prime factor

    /*打表把素数能组合的数先设置成相应的位数*/ /* if n equals two and n is No.1 position of prime factors  so four position ...

  9. [暑假集训--数论]hdu2136 Largest prime factor

    Everybody knows any number can be combined by the prime number. Now, your task is telling me what po ...

随机推荐

  1. Error 2503 and 2502 when installing/uninstalling on Windows 10

    1. Hold Ctrl+Shift and press Esc. 2. Locate “Windows Explorer” under “Windows processes”, now right ...

  2. Delphi WebBrowser 无法调用当前浏览器的版本 --转

    出自:http://blog.csdn.net/wensibo/article/details/25971863 procedure TregedtIE.FormCreate(Sender: TObj ...

  3. 【转】UNITY之LUA加密

    来自:Lua加密 两种方式:一种用luac,一种用luajit luac加密: 1.lua本身可以使用luac将脚本编译为字节码(bytecode)从而实现加密,去官网下载Lua源代码包(http:/ ...

  4. MeToo, one year on

    表示转折/让步关系:but, however, nevertheless, whereas, although, despite, in spite of, still 表示比较或对比关系:simil ...

  5. 趣味编程:静夜思(JOOL版)

    JOOL <dependency> <groupId>org.jooq</groupId> <artifactId>jool</artifactI ...

  6. Quartz+TopShelf实现Windows服务作业调度

    Quartz:首先我贴出来了两段代码(下方),可以看出,首先会根据配置文件(quartz.config),包装出一个Quartz.Core.QuartzScheduler instance,这是一个调 ...

  7. 【346】TF-IDF

    Ref: 文本挖掘预处理之向量化与Hash Trick Ref: 文本挖掘预处理之TF-IDF Ref: sklearn.feature_extraction.text.CountVectorizer ...

  8. Away3D 学习笔记(一): 加载3DS格式的模型文件

    加载外部的3DS文件分为两种: 1: 模型与贴图独立于程序的,也就是从外部的文件夹中读取 private function load3DSFile():Loader3D { loader = new ...

  9. cocos2d-x 3.0 学习笔记: 一个可以拖拽的Label及schedule的应用

    #ifndef _DRAGLABEL_H_ #define _DRAGLABEL_H_ #include "cocos2d.h" USING_NS_CC; class DragLa ...

  10. Java中static代码块,{}大括号代码块,构造方法代码块执行顺序!

    注:下列代码中的注释都是JUnit4单元测试运行结果. 首先,没有父类的(父类是Object)的类A package Static.of; public class A { { System.out. ...