ACM2136
/*
Problem Description
Everybody knows any number can be combined by the prime number.
Now, your task is telling me what position of the largest prime factor.
The position of prime 2 is 1, prime 3 is 2, and prime 5 is 3, etc.
Specially, LPF(1) = 0. Input
Each line will contain one integer n(0 < n < 1000000). Output
Output the LPF(n). Sample Input
1
2
3
4
5 Sample Output
0
1
2
1
3
*/
#include <stdio.h>
#include <string.h> const int N = ;
int hash[N+];
int prime[N+]; void sushu()
{
int i,j;
memset(prime,,sizeof(prime));
hash[] = ;
int flag = ;
for(i = ; i<=N; i++)
{
if(!prime[i])
{
hash[i] = ++flag;
for(j = i; j<=N; j+=i)
{
prime[j] = i;
}
}
}
} int main()
{
int i;
memset(hash,,sizeof(hash));
sushu();
while(~scanf("%d",&i))
{
if(i == )
printf("0\n");
else
{
int k = prime[i];
printf("%d\n",hash[k]);
}
} return ;
}
ACM2136的更多相关文章
随机推荐
- hadoop2.2.0 MapReduce分区
package com.my.hadoop.mapreduce.partition; import java.util.HashMap;import java.util.Map; import org ...
- MVC 模板页和布局
我们在以前的Asp.NET课程中已经学习过母版页了,在MVC中WebForm视图使用母版页的方法与以前基本相同. 创建一个项目MvcMasterPageDemo. 添加Home控制器,生成Index视 ...
- Linux命令之exit
本文链接:http://codingstandards.iteye.com/blog/836625 (转载请注明出处) 用途说明 exit命令用于退出当前shell,在shell脚本中可以终止当前 ...
- [Redux] Implementing combineReducers() from Scratch
The combineReducers function we used in previous post: const todoApp = combineReducers({ todos, visi ...
- sql列转行
1.需要实现一个单行的统计报表 思路先用一个union查出单列,然后再把单列转成单行 2.实现 SELECT MAX(CASE WHEN type = 1 THEN num ELSE 0 END) A ...
- xml的加密和解密
xml加密(XML Encryption)是w3c加密xml的标准.这个加密过程包括加密xml文档的元素及其子元素,通过加密,xml的初始内容将被替换,但其xml格式仍然被完好的保留. 介绍我们有3个 ...
- MySQL 加密/压缩函数
这些问题可能导致数据值的改变.一般而言,上述问题可能在你使用非二进制串数据类型(如char,varchar,text等数据类型)的情况下发生. AES_ENCRYPT()和AES_DECRYPT() ...
- (第二章)Java并发机制的底层实现原理
一.概述 Java代码在编译后会变成Java字节码,字节码被类加载器加载到JVM里,JVM执行字节码,最终需要转化为汇编指令在CPU上执行,Java中所使用的并发机制依赖于JVM的实现和CPU的指令. ...
- Linux如何创建一个新进程
2016-03-31 张超<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 Linux如何创建一个新进程 ...
- IIS7 常用模块介绍说明
1.1.0 IIS常用的功能模块介绍: 1) 静态内容:可发布静态 Web 文件格式,比如 HTML 页面和图像文件. 2) 默认文档:允许您配置当用户未在 URL ...