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. ruby简单的基本 6

    模 像类似的模块,那里 class method 和 instance method.module 没有new不能生成对象的例子其中 class method 所谓的模块在模块化的方法,它能够直接调用 ...

  2. SSIS从理论到实战,再到应用

    原文:SSIS从理论到实战,再到应用 一,是什么(What?) 1.SSIS是Microsoft SQL Server Integration Services的简称,是生成高性能数据集成解决方案(包 ...

  3. 浅谈JavaScript中typeof与instanceof的区别

      首先,我们从其常规定义入手:       instanceof 运算符可以用来判断某个构造函数的 prototype 属性是否存在另外一个要检测对象的原型链上.(需要注意的一点是:prototyp ...

  4. ListView排序并隔色显示

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.C ...

  5. CSS3+HTML5特效5 - 震动的文字

    先看效果(把鼠标移上去看看) abcd 这个效果很简单,就是移动文字的位置模拟出震动的效果. Css <style> @-webkit-keyframes shake { 0%{ -web ...

  6. angularJS之使用指令封装DOM操作

    angularJS之使用指令封装DOM操作 创建指令 指令也是一种服务,只是这种服务的定义有几个特殊要求: 必须使用模块的directive()方法注册服务 必须以对象工厂/factory()方法定义 ...

  7. C语言 ## __VA_ARGS__ 宏

    在GNU C中,宏可以接受可变数目的参数,就象函数一样 可以把__VA_ARGS__看成是将...赋值给该宏 //注意这里不能在函数中调用abc() #include <stdio.h> ...

  8. checkbox属性checked="checked"但状态不是勾选状态的解决办法

    原因: jQuery API明确说明,1.6+的jQuery要用prop,不能用attr否则无效,尤其是checkBox的checked的属性的判断.

  9. Hibernat之关系的处理一对一处理

    第一步:编写两个pojo,比如一个学生表一个班级表  这里使用注解. 需要 公司表: package com.qcf.pox; import javax.persistence.CascadeType ...

  10. Windows下一个ROracle安装与使用

    ROracle一个简短的引论: ROracle这是R连接到接入Oracle数据库DBI(Oracledatabase interface)介面.这是基于OCI一个DBI兼容Oracle司机. 具体见说 ...