Pagini recente » Cod sursa (job #1417162) | Cod sursa (job #101025) | Cod sursa (job #1642254) | Cod sursa (job #2315778) | Cod sursa (job #2315739)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("indep.in");
ofstream fout("indep.out");
const int DIM = 100;
const int B = 1e9;
struct Huge{
int V[DIM];
void init(){
for( int i = 0; i < DIM; i++ )
V[i] = 0;
V[0] = 1;
}
Huge(){
init();
}
void operator += ( Huge A ){
V[0] = max( V[0], A.V[0] );
int t = 0;
for( int i = 1; i <= V[0]; i++ ){
V[i] = V[i] + A.V[i] + t;
t = V[i] / B;
V[i] %= B;
}
while( t != 0 ){
V[ ++V[0] ] = t % B;
t /= B;
}
}
void set_scalar( int x ){
init();
if( x == 0 )
return;
V[0] = 0;
while( x != 0 ){
V[ ++V[0] ] = x % B;
x /= B;
}
}
void write(){
for( int i = V[0]; i >= 1; i-- ){
if( i != V[0] ){
int P = B / 10;
while( V[i] < P && P != 1 ){
fout << "0";
P /= 10;
}
}
fout << V[i];
}
fout << "\n";
}
} Dp[2][1005], Unu;
int cmmdc( int a, int b ){
int r = 0;
while( b != 0 ){
r = a % b;
a = b;
b = r;
}
return a;
}
int N, arr[505], t, mx;
int main(){
fin >> N;
for( int i = 1; i <= N; i++ ){
fin >> arr[i];
mx = max( mx, arr[i] );
}
Dp[1][ arr[1] ].set_scalar( 1 );
Unu.set_scalar( 1 );
for( int i = 2; i <= N; i++ ){
for( int j = 1; j <= mx; j++ )
Dp[t][j] = Dp[t ^ 1][j];
for( int j = 1; j <= mx; j++ ){
int nr = cmmdc( arr[i], j );
Dp[t][nr] += Dp[1 ^ t][j];
}
Dp[t][ arr[i] ] += Unu;
t ^= 1;
}
Dp[1 ^ t][1].write();
return 0;
}