B. Bash's Big Day
time limit per test:2 seconds
memory limit per test:512 megabytes
input:standard input
output:

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 ifgcd(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/problemset/problem/757/B

题意:给出n个数,求一个最大的集合并且这个集合中的元素gcd的结果不等于1。

思路:ai sign[ai]++;ai%j==0 sign[j]++,sign[ai/j]++;求最大的sign。注意sign[1]=1。时间复杂度n*sqrt(n);

代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=1e5+;
int num[MAXN],sign[MAXN];
int main()
{
int n;
scanf("%d",&n);
memset(sign,,sizeof(sign));
for(int i=; i<=n; i++)
{
scanf("%d",&num[i]);
sign[num[i]]++;
int tmp=sqrt(num[i]);
for(int j=; j<=tmp; j++)
{
if(num[i]%j==)
{
sign[j]++;
if(num[i]/j!=j) sign[num[i]/j]++;
}
}
}
sign[]=;
int ans=;
for(int i=; i<=; i++)
ans=max(ans,sign[i]);
cout<<ans<<endl;
return ;
}

Codeforces 757B. Bash's Big Day GCD的更多相关文章

  1. Codeforces 757B - Bash's Big Day(分解因子+hashing)

    757B - Bash's Big Day 思路:筛法.将所有因子个数求出,答案就是最大的因子个数,注意全为1的特殊情况. 代码: #include<bits/stdc++.h> usin ...

  2. 【codeforces 757B】 Bash's Big Day

    time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

  3. Codeforces 757B:Bash's Big Day(分解因子+Hash)

    http://codeforces.com/problemset/problem/757/B 题意:给出n个数,求一个最大的集合并且这个集合中的元素gcd的结果不等于1. 思路:一开始把素数表打出来, ...

  4. Codeforces 914D - Bash and a Tough Math Puzzle 线段树,区间GCD

    题意: 两个操作, 单点修改 询问一段区间是否能在至多一次修改后,使得区间$GCD$等于$X$ 题解: 正确思路; 线段树维护区间$GCD$,查询$GCD$的时候记录一共访问了多少个$GCD$不被X整 ...

  5. 【Codeforces 757B】 Bash's big day

    [题目链接] 点击打开链接 [算法] 若gcd(s1,s2,s3....sk) > 1, 则说明 : 一定存在一个整数d满足d|s1,d|s2,d|s3....,d|sk 因为我们要使|s|尽可 ...

  6. Codeforces Round #323 (Div. 2) C. GCD Table 暴力

    C. GCD Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/583/problem/C ...

  7. Codeforces Round #323 (Div. 2) C. GCD Table map

    题目链接:http://codeforces.com/contest/583/problem/C C. GCD Table time limit per test 2 seconds memory l ...

  8. [Codeforces 914D] Bash and a Tough Math Puzzle

    [题目链接] https://codeforces.com/contest/914/problem/D [算法] 显然 , 当一个区间[l , r]中为d倍数的数的个数 <= 1 , 答案为Ye ...

  9. Codeforces Round #651 (Div. 2) B. GCD Compression(数论)

    题目链接:https://codeforces.com/contest/1370/problem/B 题意 给出 $2n$ 个数,选出 $2n - 2$ 个数,使得它们的 $gcd > 1$ . ...

随机推荐

  1. opencv 对RGB图像直接二值化

    #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace st ...

  2. mongodb副本集的从库永久性设置setSlaveOk

    今天在生产环境下面搭了一个mongo的副本集,但开发那边要求副本集读写分离. 坑爹的是每次上副本集的时候都要设置db.getMongo().setSlaveOk()才能访问数据.感觉很是苦逼. 后来开 ...

  3. java spring bean的什么周期

    http://www.cnblogs.com/TIMHY/p/7794973.html

  4. python 自然语言处理库https://www.nltk.org/nltk_data/

    https://www.nltk.org/nltk_data/ https://github.com/hankcs/HanLP

  5. 与元素类型 "item" 相关联的 "name" 属性值不能包含 '<' 字符。

    Android Studio 打包时,报错: 与元素类型 "item" 相关联的 "name" 属性值不能包含 '<' 字符. 这个问题自己百度也没有发现 ...

  6. centos6.8下配置https服务器

    centos6.8下配置https服务器 1.1 环境 l  系统环境:内核环境为2.6.32版本  64位的CentOS release 6.8 (Final) [root@localhost ~] ...

  7. JPA in

    CriteriaBuilder.In in = criteriaBuilder.in(root.get("field1")); for (String str : arr) { i ...

  8. 过滤sql特殊字符方法集合

    /// <summary>     /// 过滤不安全的字符串    /// </summary>     /// <param name="Str" ...

  9. jfinal头像裁剪上传服务器

    前端页面完整代码,复制可用,记得导入库文件 <!DOCTYPE html> <html lang="en"> <head> <title& ...

  10. vue项目引入FastClick组件解决IOS系统下h5页面中的按钮点击延迟,连续点击无反应的问题

    异常描述: ios系统手机中访问h5页面,按钮点击有延迟,连续点击卡顿.无反应. 异常原因: 这要追溯至 2007 年初.苹果公司在发布首款 iPhone 前夕,遇到一个问题:当时的网站都是为大屏幕设 ...