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. max_element(C++)求数组最大元素

    #include<iostream> #include<vector> #include<algorithm> using namespace std; int m ...

  2. hive 的理解

    什么是Hive 转自: https://blog.csdn.net/qingqing7/article/details/79102691 1.Hive简介 Hive 是建立在 Hadoop 上的数据仓 ...

  3. Linux命令_1

    文件和目录命令 从P19开始的笔记 目标 查看目录内容 ls 切换目录 cd 创建和删除操作 touch mkdir rm 拷贝和移动文件 cp mv 查看文件内容 cat more grep 其他 ...

  4. Javascript Iterator

    [Javascript Iterator] 1.@@iterator Whenever an object needs to be iterated (such as at the beginning ...

  5. Opengl库函数列表

    http://www.cnblogs.com/GameDeveloper/archive/2012/01/07/2315867.html

  6. ORM之查询

    一.对象查询 1.正向查询 ret1=models.Book.objects.first() print(ret1.title) print(ret1.price) print(ret1.publis ...

  7. as3.0划线带撤销功能

    package com{ import flash.display.MovieClip; import flash.display.SimpleButton; import flash.events. ...

  8. ffmpeg编码中的二阻塞一延迟

    1. avformat_find_stream_info接口延迟 不论是减少预读的数据量,还是设置flag不写缓存,我这边都不实用,前者有风险,后者会丢帧,可能我还没找到好姿势,记录在此,参考:htt ...

  9. C++中的构造函数

    C++中的构造函数可以分为4类: (1)默认构造函数.以Student类为例,默认构造函数的原型为 Student()://没有参数 (2)初始化构造函数 Student(int num,int ag ...

  10. 26【python】sprintf风格的字符串

    参考资料:https://docs.python.org/3.5/library/stdtypes.html#old-string-formatting 实例 s#!/bin/python a = ( ...