Cod sursa(job #1234702)
Utilizator | Data | 27 septembrie 2014 20:42:03 | |
---|---|---|---|
Problema | Indep | Scor | 25 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.53 kb |
#include <fstream>
using namespace std;
const int NMAX = 505, GCDMAX = 1000;
int N, a[NMAX];
long long dp[NMAX][GCDMAX];
ifstream fin("indep.in");
ofstream fout("indep.out");
int Cmmdc(const int a, const int b) {
if (!b)
return a;
return Cmmdc(b, a % b);
}
int main() {
fin >> N;
for (int i = 1; i <= N; ++i) {
fin >> a[i];
dp[i][a[i]] = 1;
for (int j = 1; j < GCDMAX; ++j) {
dp[i][Cmmdc(j, a[i])] += dp[i - 1][j];
dp[i][j] += dp[i - 1][j];
}
}
fout << dp[N][1] << "\n";
return 0;
}