Pagini recente » Cod sursa (job #2244604) | Cod sursa (job #2350345) | Cod sursa (job #2469541) | Cod sursa (job #2319942) | Cod sursa (job #2315731)
#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] = A.V[0];
for( int i = 1; i <= V[0]; i++ )
V[i] = A.V[i];
}
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;
}
}
Huge operator + ( Huge A ){
Huge R;
R.V[0] = max( V[0], A.V[0] );
int t = 0;
for( int i = 1; i <= V[0]; i++ ){
R.V[i] = V[i] + A.V[i] + t;
t = R.V[i] / B;
R.V[i] %= B;
}
while( t != 0 ){
R.V[ ++R.V[0] ] = t % B;
t /= B;
}
return R;
}
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];
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] );
}
for( int i = 1; i <= N; i++ ){
for( int j = 1; j <= mx; j++ ){
if( arr[i] == j ){
Dp[t][ arr[i] ].set_scalar( 1 );
Dp[t][ arr[i] ] += Dp[1 ^ t][ arr[i] ];
}else{
int nr = cmmdc( arr[i], j );
if( nr == j )
Dp[t][nr] += Dp[1 ^ t][j];
else
Dp[t][nr] += Dp[1 ^ t][nr] + Dp[1 ^ t][j];
}
}
t ^= 1;
for( int j = 1; j <= mx; j++ )
Dp[t][j].init();
}
Dp[1 ^ t][1].write();
return 0;
}