Pagini recente » Cod sursa (job #3227316) | Cod sursa (job #1961565) | Cod sursa (job #504147) | Cod sursa (job #1068087) | Cod sursa (job #2926430)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("indep.in");
ofstream fout ("indep.out");
const int MAX_N = 505;
const int MAX_V = 1005;
int n, m, v[MAX_N];
struct MARE{
int digit[170];
inline void add_SCALAR(int val){
int t = val;
for(int i=1; i<=digit[0]; i++){
digit[i] += t;
t = digit[i] / 10;
digit[i] %= 10;
}
while(t){
digit[++digit[0]] = t%10;
t /= 10;
}
}
inline void add_MARE(const MARE &rhs){
digit[0] = max(digit[0], rhs.digit[0]);
int t = 0;
for(int i=1; i<=digit[0]; i++){
digit[i] += rhs.digit[i] + t;
t = digit[i] / 10;
digit[i] %= 10;
}
while(t){
digit[++digit[0]] = t%10;
t /= 10;
}
}
inline void reset(){
for(int i=1; i<=digit[0]; i++)
digit[i] = 0;
digit[0] = 0;
}
inline void output(){
if(!digit[0]){
fout<<0;
return;
}
for(int i=digit[0]; i>=1; i--)
fout<<digit[i];
}
} dp[2][MAX_V];
int main (){
ios_base::sync_with_stdio(false);
fin.tie(nullptr), fout.tie(nullptr);
fin>>n;
for(int i=1; i<=n; i++){
fin>>v[i];
m = max(m, v[i]);
}
bool row = false;
for(int i=1; i<=n; i++){
for(int cmmdc=1; cmmdc<=m; cmmdc++){
dp[1-row][cmmdc].reset();
dp[1-row][cmmdc].add_MARE(dp[row][cmmdc]);
}
dp[1-row][v[i]].add_SCALAR(1);
for(int cmmdc=1, nxt_cmmdc; cmmdc<=m; cmmdc++)
if(dp[row][cmmdc].digit[0] != 0){
nxt_cmmdc = __gcd(cmmdc, v[i]);
dp[1-row][nxt_cmmdc].add_MARE(dp[row][cmmdc]);
}
row ^= 1;
}
dp[row][1].output();
return 0;
}
/**
4
3 4 2 6
3 1 1
4 2
2
4
**/