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

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

Sample Output

  1. 15
  2. 105
  3.  
  4. 解题思路:素数筛选
  5.  
  6. 算法 from dd
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4.  
  5. #define N 100000
  6. #define yes '1'
  7. #define no '0'
  8. char flag[N+];
  9.  
  10. void is_prime(int n)
  11. {
  12. int i, j;
  13. memset(flag, yes, sizeof(flag));
  14. flag[]=flag[]=no;
  15. int len=sqrt(n)+;
  16. for(i=; i<len; i++)
  17. {
  18. if(flag[i]==no) continue;
  19. for(j=i+i; j<=n; j+=i)
  20. flag[j]=no;
  21. }
  22. }
  23.  
  24. int main(void)
  25. {
  26. int n;
  27. ///find the primes from 1 to n(n<=N)
  28. scanf("%d", &n);
  29. is_prime(n);
  30. for(int i=; i<=n; i++)
  31. if(flag[i]==yes)
  32. printf("%8d", i);
  33. printf("\n");
  34. return ;
  35. }

解题:

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4.  
  5. #define N 100050
  6. #define yes '1'
  7. #define no '0'
  8. char flag[N];
  9.  
  10. void is_prime(int n)
  11. {
  12. int i, j;
  13. memset(flag, yes, sizeof(flag));
  14. flag[]=flag[]=no;
  15. int len=sqrt(n)+;
  16. for(i=; i<len; i++)
  17. {
  18. if(flag[i]==no) continue;
  19. for(j=i+i; j<=n; j+=i)
  20. flag[j]=no;
  21. }
  22. }
  23.  
  24. int main()
  25. {
  26. int n;
  27. int count;
  28. int t,i,k,num;
  29. int max;
  30. scanf("%d",&t);
  31. while (t--) {
  32. scanf("%d", &n);
  33. max=;
  34. for (i=;i<n;++i) {
  35. count=;
  36. scanf("%d",&num);
  37.  
  38. is_prime(num);
  39. for(i=; i<=num; i++)
  40. if(flag[i]==yes){
  41. if(num%i==)
  42. count++;
  43. }
  44. if(count>max)
  45. {
  46. max=count;
  47. k=num;
  48. }
  49. if (count==max)
  50. {
  51. if (k>num) k=num;
  52. }
  53. }
  54. printf("%d\n",k);
  55. }
  56. return ;
  57. }

Winifred:

  1. #include <stdio.h>
  2. #include <string.h>
  3. bool f[];
  4. int T,p[];
  5.  
  6. void getprime()
  7. {
  8. int i,j;
  9. memset(f,true,sizeof(f));
  10. f[]=false;
  11. for (i=;i<=;i++)
  12. if (f[i])
  13. {
  14. for (j=i+i;j<=;j+=i) f[j]=false;
  15. }
  16. T=;
  17. for (i=;i<=;i++)
  18. if (f[i])
  19. {
  20. T++;
  21. p[T]=i;
  22. }
  23. }
  24.  
  25. int getdivnum(int x)
  26. {
  27. int ans=,tmp=x;
  28. for (int i=;i<=T;i++)
  29. {
  30. if (tmp%p[i]==)
  31. {
  32. ans++;
  33. while (tmp%p[i]==) tmp/=p[i];
  34. }
  35. if (p[i]>tmp) break;
  36. }
  37. return ans;
  38. }
  39. int main()
  40. {
  41. getprime();
  42. int cas;
  43. scanf("%d",&cas);
  44. while (cas--)
  45. {
  46. int n;
  47. scanf("%d",&n);
  48. int Max=,u;
  49. for (int i=;i<=n;i++)
  50. {
  51. int x;
  52. scanf("%d",&x);
  53. int t=getdivnum(x);
  54. if (t>Max)
  55. {
  56. Max=t;
  57. u=x;
  58. }
  59. else if (t==Max)
  60. {
  61. if (u>x) u=x;
  62. }
  63. }
  64. printf("%d\n",u);
  65. }
  66. getprime();
  67. }
  1.  

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. 一个由proguard与fastJson引起的血案(转)

    更新微信sdk导致ComposeData中的内部类ComposeDataSender方法被混淆 根本原因,fastjson使用姿势不对. 问题描述: 一个发件人列表里,应当呈现的数据(这里命名为Com ...

  2. 在MVC5中的使用Ninject

    在MVC5中的使用 Ninject 从MVC3中就开始接触Ninject这个IOC工具.也一直是MVC Framework系列书籍中推荐的IOC工具,当然还有优秀的Autofac等.性能和使用上面个有 ...

  3. java流下载

    @RequestMapping("/pluginDownload") public void pluginDownload(HttpServletResponse response ...

  4. Mac下Android配置及unity3d的导出Android

    昨晚实在弄的太晚了,费尽脑汁才弄出来. ok,关于mac下的eclipse的安卓配置,我仅仅贴一个网址,就ok了 http://developer.android.com/sdk/index.html ...

  5. Cocos2d-x3.0之路--02(引擎文件夹分析和一些细节)

    关于怎么搭建好开发环境的我就不写了,网上非常多. 那么 我们来看看 引擎文件的文件夹 所谓知己知彼 百战不殆嘛 先说一下setup.py 这个文件是有关配置的python文件,比方我们在进行andro ...

  6. android 使用asm.jar将android手机屏幕投射到电脑

    使用asm.jar将Android手机到电脑屏幕投影 有时候可能须要将手机上的一些操作投影出来,比方一些App Demo的展示等.事实上,有专门的硬件设备能干这件事儿.但不是必需专门为展示个Demo去 ...

  7. Bootstrap transition.js 插件

    Bootstrap transition.js 插件详解   Bootstrap 自带的 JavaScript 插件的动画效果几乎都是使用 CSS 过渡实现的,而其中的 transition.js 就 ...

  8. Humming Bird A20 SPI2驱动编译

    Humming Bird A20 SPI2使用编译 Yao.GUET 2014-07-17,请注明出处:http://blog.csdn.net/Yao_GUET A20上带有4个spi接口,因为Hu ...

  9. Android中利用Handler实现消息的分发机制(三)

    在第二篇文章<Android中利用Handler实现消息的分发机制(一)>中,我们讲到主线程的Looper是Android系统在启动App的时候,已经帮我们创建好了,而假设在子线程中须要去 ...

  10. 新服务器部署sqlserver之前的准备

    当你有一个新的服务器需要部署的时候,如果没有部署过的经验很可能会走很多误区,并且给以后的维护工作加大难度,我在这就把我部署服务器的一些经验跟大家分享一下. 1.登陆服务器以后先将物理盘按照64k为分配 ...