【codeforces 757B】 Bash's Big Day
time limit per test2 seconds
memory limit per test512 megabytes
inputstandard input
outputstandard 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.
【题目链接】:http://codeforces.com/contest/757/problem/B
【题解】
枚举那个最大的组的gcd是什么(枚举那个gcd的质因子就好);
所以找出1..10W里面的所有质数S;
然后枚举以S的倍数为gcd的组的大小;
取最大值就好;
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int MAXN = 1e5+100;
vector <int> v;
int n;
int a[MAXN];
int bo[MAXN];
bool is(int x)
{
int ma = sqrt(x);
rep1(i,2,ma)
if (x%i==0)
return false;
return true;
}
int main()
{
//freopen("F:\\rush.txt","r",stdin);
rep1(i,2,100000)
if (is(i))
v.pb(i);
rei(n);
rep1(i,1,n)
{
rei(a[i]);
bo[a[i]]++;
}
int len = v.size();
int ans = 1;
rep1(i,0,len-1)
{
int num = 0,x = v[i];
for (int now = x;now<=100000;now+=x)
num+=bo[now];
ans = max(ans,num);
}
printf("%d\n",ans);
return 0;
}
【codeforces 757B】 Bash's Big Day的更多相关文章
- 【Codeforces 757B】 Bash's big day
[题目链接] 点击打开链接 [算法] 若gcd(s1,s2,s3....sk) > 1, 则说明 : 一定存在一个整数d满足d|s1,d|s2,d|s3....,d|sk 因为我们要使|s|尽可 ...
- 【codeforces 757E】Bash Plays with Functions
[题目链接]:http://codeforces.com/problemset/problem/757/E [题意] 给你q个询问; 每个询问包含r和n; 让你输出f[r][n]; 这里f[0][n] ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 757A】Gotta Catch Em' All!
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- Scala中的“=>”和“<-”
“=>”符号大概可以看做是创建函数实例的语法糖,例如 args.foreach(arg => println(arg)) 大概可以看做 args.foreach(Function(arg) ...
- 【例题 8-1 UVA 120 】Stacks of Flapjacks
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 从大到小安排. 显然想让第i大的数字归位 只要让他翻到最上面,然后再翻回来就ok了 即operate(pos[i]) -> o ...
- pycharm快捷键、经常使用设置、配置管理
http://blog.csdn.net/pipisorry/article/details/39909057 本博客一直在同步更新中! 内容包括:pycharm学习技巧 Learning tips. ...
- LayoutAnimation-容器动画
1.LayoutAnimation的作用主要就是加载到一个layout上,让这个layout里面的所有控件都有相同的动画效果.现在用到的是在listview中添加动画,使得它每一个item都是滑落显示 ...
- 15个常用的javaScript正则表达式--来自于javascript公众号
摘要 收集整理了15个常用的javaScript正则表达式,其中包括用户名.密码强度.整数.数字.电子邮件地址(Email).手机号码.身份证号.URL地址. IPv4地址. 十六进制颜色. 日期. ...
- Monkey (压力测试)-移动端手机压力测试工具 monkey以及monkeyrunner
4. Monkey (压力测试) 这个是Android提供的系统工具.它向系统发送伪随机的用户事件流(如按键输入.触摸屏输入.手势输入等),实现对正在开发的应用程序进行压力测试.Monkey测试是一种 ...
- 【CS Round #46 (Div. 1.5) B】Letters Deque
[链接]h在这里写链接 [题意] 让你把一个正方形A竖直或水平翻转. 问你翻转一次能不能把A翻转成B [题解] 有说一定要恰好为1次. 并不是说A和B相同就一定不行. [错的次数] 2 [反思] 自己 ...
- 将一个类写成WebService服务的形式
WebService是一种跨编程语言和跨操作系统平台的远程调用技术,主要解决不同语言写的应用程序之间.不同平台(linux/windows/andrid)之间的通信,即异构系统之间的通信. 常用的天气 ...
- [D3] Build a Column Chart with D3 v4
Column and bar charts are staples of every visualization library. They also make a great project for ...
- UVa第五章STL应用 习题((解题报告))具体!
例题5--9 数据库 Database UVa 1592 #include<iostream> #include<stdio.h> #include<string.h&g ...