Cod sursa(job #1342873)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 14 februarie 2015 16:51:28
Problema Indep Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <bits/stdc++.h>

using namespace std;

const int Vmax = 1000;

int dp[2][Vmax + 1];
int N;

int main()
{
    ifstream in("indep.in");
    ofstream out("indep.out");

    ios_base::sync_with_stdio(false);

    in >> N;

    for ( int i = 1; i <= N; ++i )
    {
        int value;
        int cr = i & 1;
        int pr = cr ^ 1;

        in >> value;

        dp[cr][value]++;

        for ( int j = 1; j <= Vmax; ++j )
        {
            int GCD = __gcd(j, value);

            dp[cr][GCD] += dp[pr][j];
        }

        for ( int j = 1; j <= Vmax; ++j )
            dp[pr][j] = dp[cr][j];
    }

    out << dp[N & 1][1] << "\n";

    return 0;
}