CodeForces-757B Bash's Big Day
题目链接
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的更多相关文章
- Codeforces 757B - Bash's Big Day(分解因子+hashing)
757B - Bash's Big Day 思路:筛法.将所有因子个数求出,答案就是最大的因子个数,注意全为1的特殊情况. 代码: #include<bits/stdc++.h> usin ...
- 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 ...
- 【codeforces 757B】 Bash's Big Day
time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...
- Codeforces 757B:Bash's Big Day(分解因子+Hash)
http://codeforces.com/problemset/problem/757/B 题意:给出n个数,求一个最大的集合并且这个集合中的元素gcd的结果不等于1. 思路:一开始把素数表打出来, ...
- 【Codeforces 757B】 Bash's big day
[题目链接] 点击打开链接 [算法] 若gcd(s1,s2,s3....sk) > 1, 则说明 : 一定存在一个整数d满足d|s1,d|s2,d|s3....,d|sk 因为我们要使|s|尽可 ...
- Codeforces E. Bash Plays with Functions(积性函数DP)
链接 codeforces 题解 结论:\(f_0(n)=2^{n的质因子个数}\)= 根据性质可知\(f_0()\)是一个积性函数 对于\(f_{r+1}()\)化一下式子 对于 \[f_{r+1} ...
- [Codeforces 914D] Bash and a Tough Math Puzzle
[题目链接] https://codeforces.com/contest/914/problem/D [算法] 显然 , 当一个区间[l , r]中为d倍数的数的个数 <= 1 , 答案为Ye ...
- [Codeforces 757E] Bash Plays with Functions (数论)
题目链接: http://codeforces.com/contest/757/problem/E?csrf_token=f6c272cce871728ac1c239c34006ae90 题目: 题解 ...
- Codeforces 914D - Bash and a Tough Math Puzzle 线段树,区间GCD
题意: 两个操作, 单点修改 询问一段区间是否能在至多一次修改后,使得区间$GCD$等于$X$ 题解: 正确思路; 线段树维护区间$GCD$,查询$GCD$的时候记录一共访问了多少个$GCD$不被X整 ...
- Codeforces.914D.Bash and a Tough Math Puzzle(线段树)
题目链接 \(Description\) 给定一个序列,两种操作:一是修改一个点的值:二是给一个区间\([l,r]\),问能否只修改一个数使得区间gcd为\(x\). \(Solution\) 想到能 ...
随机推荐
- SecureCRT 设置
- javaweb基础(39)_数据库连接池
一.应用程序直接获取数据库连接的缺点 用户每次请求都需要向数据库获得链接,而数据库创建连接通常需要消耗相对较大的资源,创建时间也较长.假设网站一天10万访问量,数据库服务器就需要创建10万次连接,极大 ...
- caffe在 14.04安装
同事安装遇到的问题,记录一下 需要把cuda里面带的opengl不安装才行,否则冲突.在安装时,首先和之前一样,切换到无图形界面,关掉lightdm,安装cuda时选择--no-opengl-lib, ...
- AsyncDisplayKit技术分析
转载请注明出处:http://xujim.github.io/ios/2014/12/07/AsyncDisplayKit_inside.html ,谢谢 前言 Facebook前段时间发布了其iOS ...
- Mybatis基础入门学习
Mybatis基础入门学习 mybatis架构分析 搭建测试mybatis架构 )下载并导入mybatis3.2.7.jar(架构),mysql-connector-java-5.1.7-bin.ja ...
- 爬虫学习(十八)——selenium解决javascript渲染
selenium 是一个用于Web应用程序测试的工具. Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包括IE(7, 8, 9, 10, 11),Mozilla Fir ...
- Linux中的代码编辑器vim
Vim的三种工作模式 命令行模式 插入模式 底行模式 Vim 的命令行模式 命令行模式是进入vim后的初始模式,在该模式下主要是使用方向键来移动光标的位置,并通过相应的命令来进行文字的编辑. 切换方法 ...
- python之微信好友统计信息
需要安装库:wxpy 代码如下: from wxpy import Bot,Tuling,embed,ensure_one bot = Bot(cache_path=True) #获取好友信息 bot ...
- 493. Reverse Pairs
// see more at https://www.youtube.com/watch?v=j68OXAMlTM4 // https://leetcode.com/problems/reverse- ...
- P2158 [SDOI2008] (欧拉函数
题目描述 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是否整齐(如下图 ...