SZU:A25 Favorite Number
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的更多相关文章
- SZU:J38 Number Base Conversion
Judge Info Memory Limit: 32768KB Case Time Limit: 1000MS Time Limit: 1000MS Judger: Number Only Judg ...
- JavaScript Math和Number对象
目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...
- Harmonic Number(调和级数+欧拉常数)
题意:求f(n)=1/1+1/2+1/3+1/4-1/n (1 ≤ n ≤ 108).,精确到10-8 (原题在文末) 知识点: 调和级数(即f(n))至今没有一个完全正确的公式, ...
- Java 特定规则排序-LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- Eclipse "Unable to install breakpoint due to missing line number attributes..."
Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...
- 移除HTML5 input在type="number"时的上下小箭头
/*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...
- 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.免费应用程序调试最 ...
- 有理数的稠密性(The rational points are dense on the number axis.)
每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.
- [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
随机推荐
- OCP读书笔记(27) - 题库(ExamG)
601.You need to perform a block media recovery on the tools01.dbf data file in the SALES database by ...
- freemarker定义自己的标签错误(一)
freemarker定义自己的标记 1.错误描写叙述 freemarker.core.ParseException: Token manager error: freemarker.core.Toke ...
- oracle修改表空间
1.其中表中查找该表空间不正确 select * from dba_tables where tablespace_name='TDB'; 2.将表空间在 TDB 中的移到表空间 TDB2009 中 ...
- SpringMVC访问静态资源[转]
1.如果只配置拦截类似于*.do格式的url,则对静态资源的访问是没有问题的,如下: <!-- SpringMVC核心分发器 --> <servlet> <servlet ...
- JavaScript中获取当前项目的绝对路径
近期在做JavaWeb项目相关的东西,差点儿每天都遇到非常多问题,主要是由于自己对JavaWeb方面的知识不是非常清楚,尽量把自己在项目中遇到的问题都记录下来,方便以后查阅. 在我们的项目中有这种须要 ...
- 【百度地图API1.1】修改文本标注的样式
原文:[百度地图API1.1]修改文本标注的样式 百度地图API1.0中文本标注的样式写法为: label.getDom().style.borderColor = "#808080&quo ...
- BAT 特殊符号总结
原文:BAT 特殊符号总结 BAT特殊符号总结,用好特殊符号,利用提高开发效率.^ 转义符 用在特殊符号之前 比如: echo 非常^&批处理 如果不加^ 那么"批处理"将 ...
- iOS程序发布时出现your application is being uploaded解决办法
当用Xcode发布app时候出现“your application is being uploaded”或者用Application Loader 一直出现“ 正在通过ITUNES STORE进行鉴定 ...
- server正式的环境性能测试nginx-php 指着寻求突破的表现
因为我是第三级城市语言.无法接触到更牛接触逼公司或环境.这是你母亲的现场环境摸过几次.截至完毕,测试已设法提高空间. 公司须要的站点执行环境.不能由于我这边的瓶颈而阻碍了公司进行,希望各位大能能不吝惜 ...
- CSS3 选择器读解
文章资料来自于W3Cfuns CSS3.0 四个基本的结构性伪类选择器:root 此选择器将绑定到页面的根元素中,所谓根元素,是指文档树中最顶层的元素,也就是<html>部 分. < ...