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 ...
随机推荐
- 离线dfs CF div2 707 D
http://codeforces.com/contest/707/problem/D 先说一下离线和在线:在线的意思就是每一个询问单独处理复杂度O(多少多少),离线是指将所有的可能的询问先一次都处理 ...
- 简单的js实现网页时钟
js实现时钟. <div id="clock"></div> <script type="text/javascript"> ...
- nullable,kindof,泛型新特性
文章来自: http://blog.csdn.net/majiakun1/article/details/46530245 Overview 自 WWDC 2015 推出和开源 Swift 2.0 后 ...
- (转)Eclipse中使用Ant
Eclipse中使用Ant 分类: JAVA 工具 服务器2014-08-05 09:59 5507人阅读 评论(0) 收藏 举报 anteclipse http://286.iteye.com/bl ...
- MIME (Multipurpose Internet Mail Extensions) 是描述消息内容类型的因特网标准
http://www.alixixi.com/program/a/2010080364045.shtml MIME 消息能包含文本.图像.音频.视频以及其他应用程序专用的数据. 官方的 MIME 信息 ...
- java采用Apache FileUpload组件实现上传
可见:FileItemSteam(servletFileUpload.getItemIterator(httpServletRequest))速度要快于FileItem(servletFileUplo ...
- CSS的三种手段让元素脱离标准本文档流——浮动、绝对定位、固定定位
1.浮动 浮动是CSS中用到的最多的一个选项,他有三个性质.关于浮动我们要强调一点,永远不是一个东西单独浮动,浮动都是一起浮动,要浮动,大家都浮动. 1.1 浮动元素脱离标准文档流 1.1.1 大概描 ...
- java 读excel xlsx
http://bbs.csdn.net/topics/380257685 import java.io.File; import java.io.IOException; import java.io ...
- zookeoper在root下设置开机启动
1 准备工作 1) 切换到/etc/rc.d/init.d/目录下 2) 创建zookeeper文件:touch zookeeper 3)更新权限:chmod +777 zookeeper 4)编辑文 ...
- vim vimgdb reg 编译安装
在各种无法忍受下,还是决心自己编译安装一个vim.由于vimgdb for 7.3的patch一直有点问题,因此还是选择了vim7.2做为编译安装的版本.(1)获取vim7.2: http://www ...