zoukankan      html  css  js  c++  java
  • 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;
    }
    
    
  • 相关阅读:
    面试题27:二叉树的镜像
    面试题26:树的子结构
    面试题25:合并两个排序的链表
    面试题24:反转链表
    面试题23:链表中环的入口节点
    面试题22:链表中倒数第k个节点
    欧拉函数的使用
    C++ STL 全排列函数详解
    Ubuntu系统安装网易云音乐、搜狗输入法
    Ubuntu系统 安装谷歌 Chrome 浏览器
  • 原文地址:https://www.cnblogs.com/artoriax/p/10373888.html
Copyright © 2011-2022 走看看