题目链接

https://vjudge.net/problem/CodeForces-757B

题目

Description

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 \({s_1, s_2, s_3, ..., s_k}\)tend to fight among each other if gcd\((s_1, s_2, s_3, ..., s_k)\) = 1 (see notes for gcddefinition).

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 ≤ \(10^5\)), the number of Pokemon in the lab.

The next line contains n space separated integers, where the i-th of them denotes \(s_i(1 ≤ s_i ≤ 10^5)\), 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$ {a_1, a_2, ..., a_n}$ is the maximum positive integer that divides all the integers \({a_1, a_2, ..., a_n}\).

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.

题意

给你n个数字,选取其中gcd不为1的部分取走,问最多可以取走多少个

题解

即看分解质因数后最多的质因数出现的次数,即为最多可以取走的数量

AC代码

#include <iostream>
#include <cstdio>
#include <set>
#include <cstdlib>
#include <cstring>
#define N 100050
using namespace std;
int a[N];
int num[N];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j * j <= a[i]; j++) {
if (a[i] % j == 0) {
num[j]++;
if (j * j != a[i]) num[a[i] / j]++;
}
}
}
int ans = 1;
for (int i = 2; i < N; i++) {
ans = max(ans, num[i]);
}
cout << ans;
return 0;
}

CodeForces-757B Bash's Big Day的更多相关文章

  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 GCD

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

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

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

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

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

  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 E. Bash Plays with Functions(积性函数DP)

    链接 codeforces 题解 结论:\(f_0(n)=2^{n的质因子个数}\)= 根据性质可知\(f_0()\)是一个积性函数 对于\(f_{r+1}()\)化一下式子 对于 \[f_{r+1} ...

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

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

  8. [Codeforces 757E] Bash Plays with Functions (数论)

    题目链接: http://codeforces.com/contest/757/problem/E?csrf_token=f6c272cce871728ac1c239c34006ae90 题目: 题解 ...

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

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

  10. Codeforces.914D.Bash and a Tough Math Puzzle(线段树)

    题目链接 \(Description\) 给定一个序列,两种操作:一是修改一个点的值:二是给一个区间\([l,r]\),问能否只修改一个数使得区间gcd为\(x\). \(Solution\) 想到能 ...

随机推荐

  1. Spring是如何管理Bean

    容器是什么?spring中是如何体现的?一直有疑惑,这两天看了一下Spring管理bean的Demo,对于Spring中的容器有了简单的认识. 我们知道,容器是一个空间的概念,一般理解为可盛放物体的地 ...

  2. Python 爬虫的工具列表

    这个列表包含与网页抓取和数据处理的Python库 网络 通用 urllib -网络库(stdlib). requests -网络库. grab - 网络库(基于pycurl). pycurl - 网络 ...

  3. SpringBoot学习11:springboot异常处理方式1(自定义异常页面)

    SpringBoot 默认的处理异常的机制:SpringBoot 默认的已经提供了一套处理异常的机制.一旦程序中出现了异常 SpringBoot 会向/error 的 url 发送请求.在 sprin ...

  4. C编程经验总结5(剧终)

    Prolog是AI编程语言 Git(分布式)  svn(集中式)   commit(委托,犯罪) patch补丁)  merge(融入) repository(仓库) Ctrl+s(保存)     r ...

  5. JS底层挖掘

    //Promise版本的Ajaxconst getJSON = function(url) { const promise =new Promise(function(resolve, reject) ...

  6. python导包语句执行

    今天在做项目中遇到一个问题,在first_page中引用login的登录方法,第一次执行登录可以正常登录,登录成功后,再选择返回主菜单,回到上个页面,再选择登录时报错“login_class isno ...

  7. Javascript简单特效及摘要

    1.js中的Element对象 ** var input1=docuemnt.getElementById("input1"); //alert(input1.value); // ...

  8. MPP(大规模并行处理)

    1. 什么是MPP? MPP (Massively Parallel Processing),即大规模并行处理,在数据库非共享集群中,每个节点都有独立的磁盘存储系统和内存系统,业务数据根据数据库模型和 ...

  9. Hive学习路线图

  10. Hadoop环境搭建 (伪分布式搭建)

    一,Hadoop版本下载 建议下载:Hadoop2.5.0 (虽然是老版本,但是在企业级别中运用非常稳定,新版本虽然添加了些小功能但是版本稳定性有带与考核) 1.下载地址: hadoop.apache ...