Judge Info

  • Memory Limit: 32768KB
  • Case Time Limit: 10000MS
  • Time Limit: 10000MS
  • Judger: Number Only Judger

Description

Frog Frank likes 30 more than likes 40, yet he likes 12 and 39 equally. This is because he likes numbers that have a lot of different prime factors. For example, 30 have 3 prime factors (2,3 and 5) and 40 have 2(2 and 5) only. A prime number is a number that can be divided evenly only by itself and 1.

Task

You are given a list of numbers, find out which of the numbers Frank likes most. If there are more than one solutions, output the smallest.

Input

The first line of input contains , the number of test cases. First line of each test case contains a integers . The following line contains N positive integers, all of them are not greater than 100, 000.

Output

For each test case, print a line contains the solution.

Sample Input

2
10
3 5 7 9 11 13 15 17 19 21
11
2 4 6 8 10 13 39 105 200 201 143

Sample Output

15
105 解题思路:素数筛选 算法 from dd:
 #include <stdio.h>
#include <string.h>
#include <math.h> #define N 100000
#define yes '1'
#define no '0'
char flag[N+]; void is_prime(int n)
{
int i, j;
memset(flag, yes, sizeof(flag));
flag[]=flag[]=no;
int len=sqrt(n)+;
for(i=; i<len; i++)
{
if(flag[i]==no) continue;
for(j=i+i; j<=n; j+=i)
flag[j]=no;
}
} int main(void)
{
int n;
///find the primes from 1 to n(n<=N)
scanf("%d", &n);
is_prime(n);
for(int i=; i<=n; i++)
if(flag[i]==yes)
printf("%8d", i);
printf("\n");
return ;
}

解题:

 #include <stdio.h>
#include <string.h>
#include <math.h> #define N 100050
#define yes '1'
#define no '0'
char flag[N]; void is_prime(int n)
{
int i, j;
memset(flag, yes, sizeof(flag));
flag[]=flag[]=no;
int len=sqrt(n)+;
for(i=; i<len; i++)
{
if(flag[i]==no) continue;
for(j=i+i; j<=n; j+=i)
flag[j]=no;
}
} int main()
{
int n;
int count;
int t,i,k,num;
int max;
scanf("%d",&t);
while (t--) {
scanf("%d", &n);
max=;
for (i=;i<n;++i) {
count=;
scanf("%d",&num); is_prime(num);
for(i=; i<=num; i++)
if(flag[i]==yes){
if(num%i==)
count++;
}
if(count>max)
{
max=count;
k=num;
}
if (count==max)
{
if (k>num) k=num;
}
}
printf("%d\n",k);
}
return ;
}

Winifred:

 #include <stdio.h>
#include <string.h>
bool f[];
int T,p[]; void getprime()
{
int i,j;
memset(f,true,sizeof(f));
f[]=false;
for (i=;i<=;i++)
if (f[i])
{
for (j=i+i;j<=;j+=i) f[j]=false;
}
T=;
for (i=;i<=;i++)
if (f[i])
{
T++;
p[T]=i;
}
} int getdivnum(int x)
{
int ans=,tmp=x;
for (int i=;i<=T;i++)
{
if (tmp%p[i]==)
{
ans++;
while (tmp%p[i]==) tmp/=p[i];
}
if (p[i]>tmp) break;
}
return ans;
}
int main()
{
getprime();
int cas;
scanf("%d",&cas);
while (cas--)
{
int n;
scanf("%d",&n);
int Max=,u;
for (int i=;i<=n;i++)
{
int x;
scanf("%d",&x);
int t=getdivnum(x);
if (t>Max)
{
Max=t;
u=x;
}
else if (t==Max)
{
if (u>x) u=x;
}
}
printf("%d\n",u);
}
getprime();
}
 

SZU:A25 Favorite Number的更多相关文章

  1. SZU:J38 Number Base Conversion

    Judge Info Memory Limit: 32768KB Case Time Limit: 1000MS Time Limit: 1000MS Judger: Number Only Judg ...

  2. JavaScript Math和Number对象

    目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...

  3. Harmonic Number(调和级数+欧拉常数)

    题意:求f(n)=1/1+1/2+1/3+1/4-1/n   (1 ≤ n ≤ 108).,精确到10-8    (原题在文末) 知识点:      调和级数(即f(n))至今没有一个完全正确的公式, ...

  4. Java 特定规则排序-LeetCode 179 Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  5. Eclipse "Unable to install breakpoint due to missing line number attributes..."

    Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...

  6. 移除HTML5 input在type="number"时的上下小箭头

    /*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...

  7. iOS---The maximum number of apps for free development profiles has been reached.

    真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...

  8. 有理数的稠密性(The rational points are dense on the number axis.)

    每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.

  9. [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

随机推荐

  1. SQL Server 备份和还原全攻略

    原文:SQL Server 备份和还原全攻略 一.知识点 完全备份: 备份全部选中的文件夹,并不依赖文件的存档属性来确定备份那些文件.(在备份过程中,任何现有的标记都被清除,每个文件都被标记为已备份, ...

  2. Find a way (BFS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2612 BFS搜索  目标地  并记录下来  之后再判断两段路程之和 代码: #include < ...

  3. 学习日记之单例模式和Effective C++

    单例模式(Singleton):保证一个类仅有一个实例,并提供一个訪问它的全局訪问点. (1),通常我们能够让一个全局变量使得一个对象被訪问,但它不能防止你实例化多个对象.一个最好的办法就是,让类自身 ...

  4. hdu 5066 Harry And Physical Teacher(Bestcoder Round #14)

    Harry And Physical Teacher Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  5. POJ 1742 Coins (多重背包)

    Coins Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 28448   Accepted: 9645 Descriptio ...

  6. 1006-HBase操作实战(JAVA API状态)

    一.准备阶段 开发环境: hadoop: hadoop -2.4.0 hbase: hbase -0.94.11-security eclipse:Juno Service Release 2 二.创 ...

  7. jQuery中queue和dequeue的用法

    jQuery中的queue和dequeue是一组很有用的方法,他们对于一系列需要按次序运行的函数特别有用.特别animate动画,ajax,以及timeout等需要一定时间的函数 queue和dequ ...

  8. C#按LastID进行分页——与lambda形成链式

    public static class PageHelper { /// <summary> /// 按页码分页 /// </summary> /// <param na ...

  9. AngularJS 疑难问题解决汇总

    AngularJS 防止页面闪烁的方法 angularjs filter 详解 学习资料1 学习资料2 在 AngularJS 应用中处理单选框和复选框 学习资料3 AngularJS 之 Facto ...

  10. 实战parse_ini_file()及扩展函数解析ini文件完整版

    文章来源:PHP开发学习门户 地址:http://www.phpthinking.com/archives/587 在PHP站点开发的过程中,往往会用到读取ini參数配置文件,比方须要訪问一些复杂的借 ...