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\) 想到能 ...
随机推荐
- 2018.8.4session的removeAttribute()和invalidate()的区别
session的removeAttribute()和invalidate()的区别 session.invalidate()是销毁跟用户关联session,例如有的用户强制关闭浏览器,而跟踪用户的信息 ...
- 【洛谷P1948】[USACO08JAN]电话线
电话线 题目链接:https://www.luogu.org/problemnew/show/P1948 二分答案+最短路 我们要求一条1~n的路径,使其中的第k+1大的数最小. 二分第k+1大的数的 ...
- 【书籍连载】《STM32 HAL 库开发实战指南—基于F7》-第一章
从今天起,每天开始连载一章<STM32 HAL 库开发实战指南—基于F7>.欢迎各位阅读.点评.学习. 第1章 如何使用本书 1.1 本书的参考资料 本书参考资料为:<STM32 ...
- EBS并发管理器启动失败,系统暂挂,在重置计数器之前修复管理程序
今天EBS安装补丁之后,因为停并发管理器的时候,因为关闭EBS应用时,并发管理器没有在前台停止,就直接停了应用服务,导致启动时,并发管理器直接起不来了,使用adcmctl.sh也没有办法启动. 进入系 ...
- Spring的jdbcTemplate 与原始jdbc 整合c3p0的DBUtils 及Hibernate 对比 Spring配置文件生成约束的菜单方法
以User为操作对象 package com.swift.jdbc; public class User { private Long user_id; private String user_cod ...
- Python 初始—(迭代器和生成器)
生成器也是一个迭代器,通过next()函数实现按需计算下一个数据列表生成器,使代码变得更加简洁,只记录当前的位置,只有__next__(), (i*2 for i in range(10)) 生成器( ...
- JS - 把类似document.querySelectorAll(".xxx")、document.getElementsByName("xxx")这种方法的返回结果转换成数组对象
var btns = document.querySelectorAll(".btn");console.log(btns instanceof Array); // falseb ...
- 神经网络系列学习笔记(一)——神经网络之ANN学习资料汇总
ANN tutorial: http://adventuresinmachinelearning.com/neural-networks-tutorial/ https://www.cs.toront ...
- libvirt笔记(未完待续)
参考源地址:http://libvirt.org/formatdomain.html http://blog.csdn.net/qq250941970/article/details/6022094 ...
- php学习【1】
1:输出语句 <?php echo "hellow world"; print "hellow world"; print_r ("helow ...