水题 第三站 HDU Largest prime factor
先写一遍思路,跟素数表很类似吧。
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的更多相关文章
- hdu Largest prime factor
类似于素数打表. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 10 ...
- 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 ...
- 2136 Largest prime factor(打表)
Problem Description Everybody knows any number can be combined by the prime number.Now, your task is ...
- 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 ...
- [暑假集训--数论]hdu2136 Largest prime factor
Everybody knows any number can be combined by the prime number. Now, your task is telling me what po ...
- 杭电 2136 Largest prime factor(最大素数因子的位置)
Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 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 ...
- (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 ...
随机推荐
- SharePoint 无法删除搜索服务应用程序
在SharePoint的使用中,经常会遇到某些服务创建失败,某些服务删除不成功的情况.这里,我们就遇到了搜索服务创建失败,然后删除也不成功,使用管理中心的UI无法删除,PowerShell命令也无法删 ...
- how to install Web logic Server (WLS)
a) Download artificts from: http://www.oracle.com/technetwork/middleware/weblogic/downloads/wls-main ...
- springboot thymeleaf和shiro标签整合
这里用的是 thymeleaf 2.x版本的 添加依赖 <dependency> <groupId>com.github.theborakompanioni</group ...
- C#中的委托(一)
一.委托 把方法作为参数传给其他方法: 二.声明委托 在C#中使用一个类时,分两个阶段.首先,需要去定义一个类,然后实例化类的一个对象(只需要静态方法除外). 使用委托也需要经过这2个步骤,首先必须定 ...
- 对于php内存释放问题
大家在使用PhpExcel类时,当打开一个比较大的excel数据文档,会出现Fatalerror: Allowed memorysize of 67108864 bytes exhausted (tr ...
- 一天搞定HTML----标签的嵌套规则06
标签的嵌套规则 代码演示 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- Python抓取成都房价信息
Python里scrapy爬虫 scrapy爬虫,正好最近成都房价涨的厉害,于是想着去网上抓抓成都最近的房价情况,顺便了解一下,毕竟咱是成都人,得看看这成都的房子我以后买的起不~ 话不多说,进入正题: ...
- Vulkan Tutorial 11 Shader modules
操作系统:Windows8.1 显卡:Nivida GTX965M 开发工具:Visual Studio 2017 与之前的图像API不同,Vulkan中的着色器代码必须以二进制字节码的格式使用,而不 ...
- Linux安装JDK完整步骤
1.检查一下系统中的jdk版本 [root@localhost software]# java -version 显示: openjdk version "1.8.0_102" O ...
- 常用数组、字符串方法总结&获取元素、DOM操作
字符串的方法.返回值.是否改变原字符串:1 charAt() 方法可返回指定位置的字符. 不改变原始字符串 JavaScript并没有一种有别于字符串类型的字符数据类型,返回的字符是长度为 1 的字符 ...