• Codecraft17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) B


    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.

    题解:寻找gcd不为1的最多组合数字

    解法:暴力的来一次啊

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 map<int,int>Mp;
     4 set<int>Se;
     5 int MAX=123456;
     6 int x[123456];
     7 int n;
     8 int main(){
     9     scanf("%d",&n);
    10     for(int i=1;i<=n;i++){
    11         scanf("%d",&x[i]);
    12         Mp[x[i]]++;
    13     }
    14     int sum=1;
    15     for(int i=2;i<MAX;i++){
    16         int cur=0;
    17         for(int j=i;j<MAX;j+=i){
    18             cur+=Mp[j];
    19         }
    20         sum=max(sum,cur);
    21     }
    22     cout<<sum<<endl;
    23     return 0;
    24 }
  • 相关阅读:
    contentEditable
    Web开发工具(插件)收集
    用limit 传变量TO 存储过程解决方案(续)
    ASP.NET1.1和ASP.NET2.0中数据库连接字符串的不同设置
    按比例微缩图片的一段小小的JS代码
    研究下市场上有哪些软件项目/产品,哪些是值得做的?
    Ajax联动下拉框的实现例子
    C#装箱与拆箱
    在VS2005连接SQL2005时不允许远程连接
    联系我们
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/7495069.html
Copyright © 2020-2023  润新知