CodeForces757B
B. Bash's Big Day
time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard outputBash 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+10; int book ; int main() { int n, a; while(scanf("%d", &n) != EOF) { memset(book, 0, sizeof(book)); for(int i = 0; i < n; i++) { scanf("%d", &a); for(int j = 1; j*j <= a; j++) { if(j*j == a) book[j]++; else if(a%j == 0) { book[j]++; book[a/j]++; } } } int ans = 1; for(int i = 2; i < N; i++) if(book[i] > ans) ans = book[i]; printf("%d\n", ans); } return 0; }
- Winform程序实现多显示屏、多屏幕显示的2种方法
- 生活,生活就是这样。面对,承受,调节,整理。
- 安装redis
- 2017.1.18【初中部 】普及组模拟赛C组 临时工计划 题解
- Mysql基础操作命令
- Mysql基础操作命令
- [oracle]索引与索引表管理
- JavaScript 中 for 循环
- JAVA基础——Java Synchronized
- CodeForces 448D - Multiplication Table(二分)
- CodeForces 593B - Anton and Lines(思维)
- HDU - 5269【SBBBBBB Trie】
- stl算法设计理念_一元函数对象和一元谓词
- Hadoop-2.7.3 单节点模式安装
- RGB图像存储为AVI?
- linux环境下的基础命令操作
- 新手进阶WebStorm工具的基本使用
- POJ 3295-Tautology(模拟-逻辑表达式)
- c++ 对一个5位数的任意整数,求出其降序数
- C#Redis哈希Hashes