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. 嵌入式 Web Server 温度检测系统

    1. Web Server 服务器后台表单处理程序:使用 CGI 程序接口编写后台程序的 Web 服务器. 2. Boa 服务器

  2. JS----贪吃蛇游戏

    在网上找到的几种例子 <!DOCTYPE html> <html > <head> <meta http-equiv="Content-Type&q ...

  3. Binary Logging Formats

    [Binary Logging Formats] The server uses several logging formats to record information in the binary ...

  4. 手机通过Charles抓取https包

      因为fiddler不能在mac上使用,而Charles是跨平台的,可以在mac上使用,所以需要了解一下Charles的使用   安装破解版Charles   下载破解版包,先启动一次未破解版的Ch ...

  5. sqlserver 当前时间减去30天

    参考 https://zhidao.baidu.com/question/750666819064717772.html select dateadd(dd,-30,getdate()) from 表 ...

  6. vue中使用全局函数

    方法一: 在mian.js中写入函数: Vue.prototype.bb = function () {        alert('OK'); } 然后在任何组件中都可以调用: this.bb() ...

  7. Unity4.6证书激活问题

    第一次运行的激活问题 安装好Unity4.6之后首次启动会自动连网,但是会出现error loading page错误,SSL peer certificate or SSH remote key w ...

  8. 方法装饰器(Decorator)

    代码: function enhance(target, key, descriptor) { const method = descriptor.value; let extraSpeed = 50 ...

  9. java发送http连接

    原生方式:@转载文章 import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamRead ...

  10. 记录下ABAP开发的一些东西(T-code居多)Updated to markdown

    几个TCODE se38 开发program,report: sa38 只运行program se37 开发function: se11/se16 管理数据字典/数据表: ko03 Internal ...