zoukankan      html  css  js  c++  java
  • 【Codeforces 757B】 Bash's big day

    【题目链接】

               点击打开链接

    【算法】

             若gcd(s1,s2,s3....sk) > 1,

             则说明 : 一定存在一个整数d满足d|s1,d|s2,d|s3....,d|sk

             因为我们要使|s|尽可能大,所以d是一个质数

             对每个数进行质因数分解即可

    【代码】

              

    #include<bits/stdc++.h>
    using namespace std;
    const int MAXN = 1e5;
    
    int N,i,j,tmp,ans;
    int a[MAXN+10],s[MAXN+10]={0,1};
     
    template <typename T> inline void read(T &x) {
            int f = 1; x = 0;
            char c = getchar();
            for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
            for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
            x *= f;
    }
    
    template <typename T> inline void write(T x) {
        if (x < 0) { putchar('-'); x = -x; }
        if (x > 9) write(x/10);
        putchar(x%10+'0');
    }
    
    template <typename T> inline void writeln(T x) {
        write(x);
        puts("");
    }
    
    int main() {
            
            read(N);
            for (i = 1; i <= N; i++) read(a[i]);
            for (i = 1; i <= N; i++) {
                    tmp = a[i];
                    for (j = 2; j <= sqrt(tmp); j++) {
                            if (!(tmp % j)) ++s[j];
                            while (!(tmp % j)) tmp /= j;
                    }
                    if (tmp > 1) ++s[tmp];
            }
            for (i = 1; i <= MAXN; i++) ans = max(ans,s[i]);
            writeln(ans);
            
            return 0;
        
    }
  • 相关阅读:
    LeetCode--Sudoku Solver
    LeetCode--Merge Intervals
    LeetCode--Valid Number
    LeetCode--Max Points on a Line
    1.1
    智能指针原理与简单实现(转)
    C++内存管理(转)
    算法题--扔棋子
    LeetCode--Substring with Concatenation of All Words
    线性代数与MATALB1
  • 原文地址:https://www.cnblogs.com/evenbao/p/9196406.html
Copyright © 2011-2022 走看看