CodeForces757B
B. Bash's Big Day
2 seconds
512 megabytes
standard input
standard output
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.
Examples
input
3
2 3 4
output
2
input
5
2 3 4 6 7
output
3
Note
gcd (greatest common divisor) of positive integers set {a1, a2, ..., an} is the maximum positive integer that divides all the integers {a1, a2, ..., an}.
In the first sample, we can take Pokemons with strengths {2, 4} since gcd(2, 4) = 2.
In the second sample, we can take Pokemons with strengths {2, 4, 6}, and there is no larger group with gcd ≠ 1.
桶排数的因子
//2016.01.18
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int N = 1e5+;
int book[N]; int main()
{
int n, a;
while(scanf("%d", &n) != EOF)
{
memset(book, , sizeof(book));
for(int i = ; i < n; i++)
{
scanf("%d", &a);
for(int j = ; j*j <= a; j++)
{
if(j*j == a)
book[j]++;
else if(a%j == )
{
book[j]++;
book[a/j]++;
}
}
}
int ans = ;
for(int i = ; i < N; i++)
if(book[i] > ans)
ans = book[i];
printf("%d\n", ans);
} return ;
}
CodeForces757B的更多相关文章
- CodeForces-757B Bash's Big Day
题目链接 https://vjudge.net/problem/CodeForces-757B 题目 Description Bash has set out on a journey to beco ...
随机推荐
- SVN第二篇-----命令集合
16.switch 代码库URL变更 svn switch (sw): 更新工作副本至不同的URL. 用法: 1.switch URL [PATH] 更新你的工作副本,映射到一个新 ...
- HUST 1353 Dartboard
构造.应该有多种构造方法.做的时候WA了好几发,怀疑做法是错的,事实上是代码写搓了.. 我是这样构造的:先从上往下左右放奇数,再从下往上左右填偶数 (一)如果n/2是偶数(以12为例) 左边列是内环, ...
- 【转】分享一份C语言写的简历
个人观点:文章想法很棒,作者的编码风格也很赞,可以从中学到不少东西.转载的文章是我都用心看过的,而且希望后续再可以回过头看的文章,努力让自己的能力越来越强,加油 这里黑客新闻吗?作者用代码更新了自己的 ...
- Java链表的一些操作:
[还有一些其他的算法提]http://blog.csdn.net/WalkingInTheWind/article/category/906980 [转]http://blog.csdn.net/lu ...
- PHP下的命令行执行
PHP 的命令行模式 以下是 PHP 二进制文件(即 php.exe 程序)提供的命令行模式的选项参数,您随时可以通过 PHP -h 命令来查询这些参数. Usage: php [options] [ ...
- LDA 线性判别分析
LDA, Linear Discriminant Analysis,线性判别分析.注意与LDA(Latent Dirichlet Allocation,主题生成模型)的区别. 1.引入 上文介绍的PC ...
- 那些年我们一起改过的bug
ORA-01861: 文字与格式字符串不匹配 ORA-00936: 缺失表达式 ORA-01810 格式代码出现两次 ORA-01722: 无效数字 无效的列索引
- shell 脚本连接mysql数据库查询database中表的数量和表名
#!/bin/bash MYSQLHOST="127.0.0.1" MYSQLUSER="root" MYSQLPWD="root" MYS ...
- Python3基础 用list()查看filter()返回的对象
镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...
- 全局文件 pch
在 bulding setting 里面 搜 prefix header 然后添加自己的pch 路径, 类似 $(SRCROOT)/... 还要把 precompile prefix header 设 ...