Cod sursa(job #3319205)

Utilizator MihneaStoicaMihnea Teodor Stoica MihneaStoica Data 31 octombrie 2025 09:43:18
Problema Indep Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <bits/stdc++.h>
using namespace std;

/**
 * Problem: Indep
 * URL: https://infoarena.ro/problema/indep
 * TL: 100 ms
 * ML: 64 MB
 *
 * Good Luck!
 */
using ll = long long;
// #define int ll
void tc() {
    int n; cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
    }
    int maxx = *max_element(a.begin() + 1, a.end());

    vector<vector<int>> dp(n + 1, vector<int>(maxx + 1));
    dp[0][0] = 1;
    for (int i = 1; i <= n; i ++) {
        for (int j = 1; j <= maxx; j ++) {
            dp[i][j] = dp[i - 1][j];
            dp[i][gcd(j, a[i])] += dp[i - 1][j];
        }
        dp[i][a[i]] ++;
    }

    int ans = 0;
    for (int i = 1; i <= n; i ++) {
        ans = max(ans, dp[i][1]);
    }
    cout << ans << '\n';
}

#define MULTITEST 0
#define FILEIO 1
#define FILE "indep"

signed main() {
#if FILEIO && !defined(LOCAL)
    (void)!freopen(FILE ".in", "r", stdin); (void)!freopen(FILE ".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#if MULTITEST
    int T; cin >> T; while (T --) tc();
#else
    tc();
#endif
    return 0;
}