先写一遍思路,跟素数表很类似吧。

1)从小到大遍历数据范围内的所有数。把包含质因子的数的位置都设成跟质因子的位置相同。

2)同一个数的位置可能被多次复写。但是由于是从小到大遍历,这就保证了最后一次写入的是该数的最大质因子的位置

一道题墨迹了好久,上代码分析

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <string.h>
using namespace std;
const int maxn=;
int a[maxn];
void prime()
{
int i,j,k=;
for(i=; i<maxn; i++)
{
if(a[i]==)
{
k++;
a[i]=k;
for(j=; j*i<maxn; j++)
{
a[i*j]=k;
}//把这个for循环是写在if里面还是外面纠结了好久,写在外面怎么可能对呢?= =
}
}
}
int main ()
{
int n;
prime();
while(~scanf("%d",&n))
{
memset(a,,sizeof());//首先刚开始把prime()写到这里了,= =怪不得超时,蠢哭 printf("%d\n",a[n]);
}
return ;
}

总之,在网上看完思路写代码的过程中也是状况百出,一年前接触过素数表,现在早都忘记了,重拾后运用的依旧不熟练啊。

水题 第三站 HDU Largest prime factor的更多相关文章

  1. hdu Largest prime factor

    类似于素数打表. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 10 ...

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

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

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

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

  4. 2136 Largest prime factor(打表)

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

  5. 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 ...

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

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

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

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

  8. 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 ...

  9. (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 ...

随机推荐

  1. Kotlin入门第二课:集合操作

    测试项目Github地址: KotlinForJava 前文传送: Kotlin入门第一课:从对比Java开始 初次尝试用Kotlin实现Android项目 1. 介绍 作为Kotlin入门的第二课, ...

  2. web 直播&即时聊天------阿里云、融云(二)

    上一篇简要主要介绍了融云制作聊天室的基本方法,这次基本属于对上一篇的补充以及进阶...^_^... (ps:吐槽一下,加了三个融云的线下qq群,全部没人解决问题,也不知道建此群的意义,若是民间的话就当 ...

  3. SSM框架中常用的注解

    @Controller:在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理层处理之后封装成一个Model , ...

  4. 第 16 章 MySQL Cluster

    前言: MySQL Cluster 是一个基于 NDB Cluster 存储引擎的完整的分布式数据库系统.不仅仅具有高可用性,而且可以自动切分数据,冗余数据等高级功能.和 Oracle Real Cl ...

  5. ArrayList构造方法源码分析

    首先看一下无参的构造方法: private static final Object[] DEFAULTCAPACITY_EMPTY_ELEMENTDATA = {}; transient Object ...

  6. jQuery-强大的jQuery选择器、过滤器

    1. 基础选择器 Basics 名称 说明 举例 #id 根据元素Id选择 $("divId") 选择ID为divId的元素 element 根据元素的名称选择, $(" ...

  7. Centos7下安装部署MXNET

    Centos下安装MXNET,参考官方文档http://mxnet.io/get_started/setup.html#prerequisites, 一.安装python的mxnet步骤如下: #!/ ...

  8. My "Top 5 R Functions"(转)

    In preparation for a R Workgroup meeting, I started thinking about what would be my "Top 5 R Fu ...

  9. nodeJS之进程process对象

    前面的话 process对象是一个全局对象,在任何地方都能访问到它,通过这个对象提供的属性和方法,使我们可以对当前运行的程序的进程进行访问和控制.本文将详细介绍process对象 概述 process ...

  10. Heartbeat高可用解决方案

    Heartbeat高可用 Heartbeat作用: 通过heartbeat,可以将资源(ip以及程序服务等资源)从一台已经故障的计算机快速转移到另一台正常运转的机器上继续提供服务,一般称之为高可用服务 ...