Bash's Big Day
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.
But Zulu warns him that a group of k > 1 Pokemon with strengths {s1, s2, s3, ..., sk} tend to fight among each other if gcd(s1, s2, s3, ..., sk) = 1 (see notes for gcd definition).
Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take?
Note: A Pokemon cannot fight with itself.
Input
The input consists of two lines.
The first line contains an integer n (1 ≤ n ≤ 105), the number of Pokemon in the lab.
The next line contains n space separated integers, where the i-th of them denotes si (1 ≤ si ≤ 105), the strength of the i-th Pokemon.
Output
Print single integer — the maximum number of Pokemons Bash can take.
Example
3
2 3 4
2
5
2 3 4 6 7
题意:
给你一组数,求出里面最大公约数不为1的最多数量。
这道题刚开始最直观思路就是两个for循环,直接查找对于每一个数都求一下。当然这肯定超时了,
后来上网搜了一下,暴力枚举就OK了,思路都差不多,但是算法改进一下,对每个输入的数字求出因子,然后对因子的数量加1,这样只用一个for循环就OK了。
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int INF = ;
int s[INF] = { };
int main()
{
int n;
cin >> n;
int m;
for (int i = ; i < n; i++)
{
scanf("%d", &m);
int j = ;
for (j = ; j * j < m; j++)//从1开始是对每个数都让自己这个数量从0变为1
{
if (m % j == )
{
s[j]++;
s[m / j]++;//因子++
}
}
if (j * j == m)
{
s[j]++;
}
}
int ans = ;
for (int i = ; i < INF; i++)
{
ans = max(ans, s[i]);
}
cout << ans << endl;
return ;
}
Bash's Big Day的更多相关文章
- scp报错 -bash: scp: command not found
环境:RHEL6.5 使用scp命令报错: [root@oradb23 media]# scp /etc/hosts oradb24:/etc/ -bash: scp: command not fou ...
- bash字符串操作
参考 http://www.cnblogs.com/chengmo/archive/2010/10/02/1841355.html 问题:bash怎么提取字符串的最后一位?例如python中strin ...
- grep 查找bash脚本中的注释代码
出于安全性的考虑,不建议在bash脚本中注释掉不使用的代码.也就是说如果某段代码不使用了,那么应该删除掉,而不是简单地注释掉.假如你突然意识到这一点,而以前并没有遵从这个原则,现在需要找出脚本中的注释 ...
- Bash 脚本编程语言中的美学与哲学
我承认,我再一次地当了标题党.但是不可否认,这一定是一篇精华随笔.在这一篇中,我将探讨 Bash 脚本语言中的美学与哲学. 这不是一篇 Bash 脚本编程的教程,但是却能让人更加深入地了解 Bash ...
- cmder git bash 使用
cmder 是一款 windows 下的命令集合软件,它可以集合各种系统下的命令,并且操作非常快速方便. 安装有两个版本,一个是简化版(4.27M),一个是完全版(75.7M),它们的唯一区别:完全版 ...
- 安装完成后在命令行运行bash时报错0x80070057
在命令运行bash 提示如下: 解决方法,不启用旧版本控制台: 右键命令提示栏 打开属性,把勾选去掉如下图红色边框标识: 然后重启,就可以使用,也包括可以打开Bash on Unbuntu on Wi ...
- Bash简明教程--变量
1. 前言 Bash是一门流行在*nix系统下的脚本语言.作为一门脚本语言,变量是一门语言的基本要素,在这篇教程中,我们将学习Bash中的变量是怎么表示的,以及变量相关的一些语法规则. 2. Bash ...
- 让BASH,VIM美美的Powerline
前言 鉴于BASH及其周边强大的工具以及VIM高效快捷,加上现在我工作重心转移到前端开发上,因此我华丽地转向Linux阵营(当然从最傻瓜式的Ubuntu开始啦!).但BASH和VIM默认样式确实颜值 ...
- 解决Bash On Ubuntu On Window安装Zsh无效问题附安装说明
前言 Zsh是一款非常棒的Shell,使用Linux和Mac系统的人,基本上都知道zsh的存在. 问题 在安装完Zsh后,zsh是可以使用的,但是重启之后,又恢复至默认的bash. 我在安装好之后,使 ...
- source /etc/profile报错-bash: id:command is not found
由于误操作导致 source /etc/profile 报错 -bash: id:command is not found 此时,linux下很多命令到不能能用,包括vi ls 等... 可以使用 e ...
随机推荐
- java集合框架list和set
为什么出现集合类? 面向对象语言对事物的体现都是以对象的形式,所以为了方便对多个对象的操作,就对对象进行存储,集合就是存储对象最常用的一中方式 数组和集合类同是容器,有何不同? 数组虽然也可以存储对象 ...
- java删除文件夹 Java中实现复制文件或文件夹
删除文件夹 import java.io.File; public class DeleteDir { /** * @param args */ public static void main(Str ...
- C#入门经典第十章类的成员-1
类成员的访问级别 public 成员可以由任何代码访问,公共的. private 私有的,成员只能有类中的代码访问.(默认的关键字) internal 内部的,成员只能有定义它的程序集(项目)内部 ...
- zf-关于荆州首页鼠标移动到导航栏上去触发的js 显示 问题解决办法
是我copy代码的 时候 这个触发的属性没有修改,导致出现BUG,改成mopen('m2') 就好了
- ural1147 Shaping Regions
Shaping Regions Time limit: 0.5 secondMemory limit: 64 MB N opaque rectangles (1 ≤ N ≤ 1000) of vari ...
- css3的apprearance属性(转)
appearance使用方法: .elmClass{ -webkit-appearance: value; -moz-appearance: value; appearance: value; } 接 ...
- eclipse的插件
jode_1.0.6(Java Optimize and Decompile Environment ) 非常好用的Eeclipse的反编译插件,随时点击,随时查看源代码,但他的官方下载的都是核心源码 ...
- Struts2--模块包含
login.xml: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUB ...
- C#读取word文件
第一步:添加对在项目引用里添加上对Microsoft Word 11.0 object library的引用.右击--引用---在com标签下添加.
- IO口输入输出模式理解
1.IO输入输出模式 2.有上拉,下拉,弱上拉,推挽,开漏输出:不同的单片机有不同的输出模式 3.以最简单的51单片机为例 P0:开漏型双向IO口,通常需要添加外部上拉电阻 P1~P3:准双向IO口, ...