看懂:

Max Factor

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3089    Accepted Submission(s): 985

Problem Description
To improve the organization of his farm, Farmer John labels each of his N (1 <= N <= 5,000) cows with a distinct serial number in the range 1..20,000. Unfortunately, he is unaware that the cows interpret some serial numbers as better than others. In particular, a cow whose serial number has the highest prime factor enjoys the highest social standing among all the other cows.
(Recall that a prime number is just a number that has no divisors except for 1 and itself. The number 7 is prime while the number 6, being divisible by 2 and 3, is not).
Given a set of N (1 <= N <= 5,000) serial numbers in the range 1..20,000, determine the one that has the largest prime factor.
 
Input
* Line 1: A single integer, N
* Lines 2..N+1: The serial numbers to be tested, one per line
 
Output
* Line 1: The integer with the largest prime factor. If there are more than one, output the one that appears earliest in the input file.
 
Sample Input
4
36
38
40
42
 
Sample Output
38
#include<stdio.h>
#include<string.h>
const int MAX=;
int s[MAX];
int main()
{
int n,m,maxn,i,j,p; memset(s,,sizeof(s));
s[]=;
for(i=;i<MAX;i++)//筛选所有范围内的素数
{
if(s[i]==)
for(j=i;j<MAX;j+=i)
{
s[j]=i;
}
}
while(~scanf("%d",&n))
{
maxn=-;
while(n--)
{
scanf("%d",&m);
if(s[m]>maxn)
{
maxn=s[m];
p=m;
}
}
printf("%d\n",p);
}
return ;
}

HDU-2710 Max Factor的更多相关文章

  1. HDOJ/HDU 2710 Max Factor(素数快速筛选~)

    Problem Description To improve the organization of his farm, Farmer John labels each of his N (1 < ...

  2. hdu 2710 Max Factor 数学(水题)

    本来是不打算贴这道水题的,自己却WA了三次.. 要考虑1的情况,1的质因子为1 思路:先打表 ,然后根据最大质因子更新结果 代码: #include<iostream> #include& ...

  3. HDU 2710 Max Factor(数论,素数筛法)

    #include<iostream> #include<stdio.h> #include<string.h> #include<cmath> usin ...

  4. 抓其根本(一)(hdu2710 Max Factor 素数 最大公约数 最小公倍数.....)

    素数判断: 一.根据素数定义,该数除了1和它本身以外不再有其他的因数. 详见代码. int prime() { ; i*i<=n; i++) { ) //不是素数 ; //返回1 } ; //是 ...

  5. HDU 1024 Max Sum Plus Plus --- dp+滚动数组

    HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值, ...

  6. HDU 1003 Max Sum --- 经典DP

    HDU 1003    相关链接   HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...

  7. HDU 1244 Max Sum Plus Plus Plus

    虽然这道题看起来和 HDU 1024  Max Sum Plus Plus 看起来很像,可是感觉这道题比1024要简单一些 前面WA了几次,因为我开始把dp[22][maxn]写成dp[maxn][2 ...

  8. hdu 3415 Max Sum of Max-K-sub-sequence(单调队列)

    题目链接:hdu 3415 Max Sum of Max-K-sub-sequence 题意: 给你一串形成环的数,让你找一段长度不大于k的子段使得和最大. 题解: 我们先把头和尾拼起来,令前i个数的 ...

  9. hdu 2993 MAX Average Problem(斜率DP入门题)

    题目链接:hdu 2993 MAX Average Problem 题意: 给一个长度为 n 的序列,找出长度 >= k 的平均值最大的连续子序列. 题解: 这题是论文的原题,请参照2004集训 ...

随机推荐

  1. thinkphp 行为扩展

    网站程序在运行的过程每个过程都可以看做是一种行为,例如:运行应用,加载类,执行方法,加载模板,解析模板等,也就是说,我们在程序执行过程中每个 步骤都可以 定义一些点,我们可以在运行 程序的时候 检查 ...

  2. Solr集群的搭建以及使用(内涵zookeeper集群的搭建指南)

    1   什么是SolrCloud SolrCloud(solr 云)是Solr提供的分布式搜索方案,当你需要大规模,容错,分布式索引和检索能力时使用 SolrCloud.当一个系统的索引数据量少的时候 ...

  3. GIS科研站

    http://www.3sbase.com/3sbase/ 近年来,地理信息科学发展迅猛,科研人员日益增多,但目前尚缺乏良好的交流平台,致使优秀的科研成果难以推广.同时,对于大量的GIS学生而言,对国 ...

  4. vs的watch使用

    VC调试器高级应用----WATCH窗口篇 一.格式化数据和表达式赋值语句. 常用变量格式化符(表达式的值后跟逗号,接格式化符,如"(int)0xFFFF,d"):d  :有符号的 ...

  5. C++学习指南

    转载于stackoverflow:http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list 感谢Ge ...

  6. URL重写 UrlRewrite

    为什么要URL重写? 1.有利于SEO,带参数的URL权重较低: 2.地址看起来更正规,推广uid 伪静态:看起来像普通页面,而非动态生成的页面. 原理:在Global.asax的Applicatio ...

  7. centOS 6 python MySQLdb 提示 no module

    http://www.cnblogs.com/czh-liyu/archive/2012/11/30/2796028.html(转) 用python连接本地数据库时,提示no module MySQL ...

  8. 嵌入式linux无线网卡的使用

    from:http://blog.csdn.net/sparksalmon/article/details/8445287 嵌入式linux无线网卡的使用 最近一直在开发机顶盒上的无线功能,把这一段的 ...

  9. java中的多线程——进度1

    import java.util.*;public static void main(String[] args) {/*final可以修饰类,方法,变量.final修饰的类不可以被继承.final修 ...

  10. JavaScript经典面试题系列

    1.javascript的typeof返回哪些数据类型 Object number function boolean underfind 2.例举3种强制类型转换和2种隐式类型转换? 强制(parse ...