zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    美剧字幕美国怪谭第一季第4集
    ios 中生成随机数
    美剧字幕绿箭侠第一季第1集
    关于iOS6应用中第三方类库不支持armv7s的问题解决
    美剧字幕美国怪谭第一季第2集
    美剧字幕美国怪谭第一季第一集
    美剧字幕美国怪谭第一季第3集
    NewWords/1100
    Developing for App StorePreparing the Development Team03
    平静(转载)
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/7495069.html
Copyright © 2011-2022 走看看