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 ...
随机推荐
- 一个由proguard与fastJson引起的血案(转)
更新微信sdk导致ComposeData中的内部类ComposeDataSender方法被混淆 根本原因,fastjson使用姿势不对. 问题描述: 一个发件人列表里,应当呈现的数据(这里命名为Com ...
- 在MVC5中的使用Ninject
在MVC5中的使用 Ninject 从MVC3中就开始接触Ninject这个IOC工具.也一直是MVC Framework系列书籍中推荐的IOC工具,当然还有优秀的Autofac等.性能和使用上面个有 ...
- java流下载
@RequestMapping("/pluginDownload") public void pluginDownload(HttpServletResponse response ...
- Mac下Android配置及unity3d的导出Android
昨晚实在弄的太晚了,费尽脑汁才弄出来. ok,关于mac下的eclipse的安卓配置,我仅仅贴一个网址,就ok了 http://developer.android.com/sdk/index.html ...
- Cocos2d-x3.0之路--02(引擎文件夹分析和一些细节)
关于怎么搭建好开发环境的我就不写了,网上非常多. 那么 我们来看看 引擎文件的文件夹 所谓知己知彼 百战不殆嘛 先说一下setup.py 这个文件是有关配置的python文件,比方我们在进行andro ...
- android 使用asm.jar将android手机屏幕投射到电脑
使用asm.jar将Android手机到电脑屏幕投影 有时候可能须要将手机上的一些操作投影出来,比方一些App Demo的展示等.事实上,有专门的硬件设备能干这件事儿.但不是必需专门为展示个Demo去 ...
- Bootstrap transition.js 插件
Bootstrap transition.js 插件详解 Bootstrap 自带的 JavaScript 插件的动画效果几乎都是使用 CSS 过渡实现的,而其中的 transition.js 就 ...
- Humming Bird A20 SPI2驱动编译
Humming Bird A20 SPI2使用编译 Yao.GUET 2014-07-17,请注明出处:http://blog.csdn.net/Yao_GUET A20上带有4个spi接口,因为Hu ...
- Android中利用Handler实现消息的分发机制(三)
在第二篇文章<Android中利用Handler实现消息的分发机制(一)>中,我们讲到主线程的Looper是Android系统在启动App的时候,已经帮我们创建好了,而假设在子线程中须要去 ...
- 新服务器部署sqlserver之前的准备
当你有一个新的服务器需要部署的时候,如果没有部署过的经验很可能会走很多误区,并且给以后的维护工作加大难度,我在这就把我部署服务器的一些经验跟大家分享一下. 1.登陆服务器以后先将物理盘按照64k为分配 ...