看懂:

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. facebook登录(集成FBSDKLoginKit) result的isCancelled总是YES token为nil

    只需要在AppDelegate如下函数添加: - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDict ...

  2. jQuery如何阻止子元素继承父元素事件?

    <a> <b></b> </a> $("a").click(...); 这种绑定的话,b也会响应一次事件,如何只对a元素绑定事件,而 ...

  3. jQuery的基础语法实例

    jQuery 基础语法 jQuery 语法是为 HTML 元素的选取编制的,可以对元素执行某些操作. 基础语法是:$(selector).action() 美元符号定义 jQuery 选择符(sele ...

  4. 03_MySQL中文乱码处理_02_确保MySQL插入数据不乱码的解决方法

    [要统一MySQL数据库客户端 和 服务端的字符集] 如下,就是不统一的情况: 通常,MySQL数据库的下面几个字符集(客户端 和 服务端)统一成一个字符集(即" show variable ...

  5. 15_动态SQL

    [UserMapper.xml]和之前的作对比 <mapper namespace="com.Higgin.Mybatis.mapper.UserMapper"> &l ...

  6. unsigned int 转 RGB

    unsigned int颜色存储格式:0xaabbggrr,其中a,b,g,r分别表示,透明度.蓝色.绿色.红色. 方法一:使用windows宏 unsigned int clr = 0x00FF00 ...

  7. SGU 280.Trade centers(贪心)

    SGU 280.Trade centers 解题报告 题意: n(<=30000)个城市,(n-1)条道路,求最少需要选择多少个城市建造市场,使得所有城市到任意一个市场的距离不大于k. Solu ...

  8. 给定任意一个字符串,使用 for in 语句来统计字符出现的个数

    //找出字符串中的数字 var str = 'haj123sdk54hask33dkhalsd879'; /*function findNum(str){ var arr = []; var tmp ...

  9. 『奇葩问题集锦』Zepto 页面唤醒拨号功能点透

    不废话直接上代码: HTML: <a class="js-tel tel" data-tel="1312414"></a> JS: // ...

  10. which命令

    which指令会在PATH变量指定的路径中,搜索某个系统命令的位置,并且返回第一个搜索结果. 格式 which 可执行文件名称 参数 -V  显示版本信息 实例 用 which 去找出 which w ...