Pagini recente » Cod sursa (job #891565) | Cod sursa (job #2545430) | Cod sursa (job #1154509) | Cod sursa (job #1148214) | Cod sursa (job #2929581)
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
using ll = long long;
using namespace std;
const int NMAX = 505;
const int GCDMAX = 1005;
/*******************************/
// INPUT / OUTPUT
ifstream f("indep.in");
ofstream g("indep.out");
/*******************************/
/// GLOBAL DECLARATIONS
int N;
int v[NMAX], x[GCDMAX][GCDMAX];
short dp[2][GCDMAX][5005], a[5005], b[5005], ans[5005];
/*******************************/
/// FUNCTIONS
void ReadInput();
void Solution();
void Output();
/*******************************/
///-------------------------------------
inline void ReadInput()
{
f >> N;
for (int i = 1 ; i <= N ; ++ i)
{
f >> v[i];
}
}
///-------------------------------------
void sum(short a[5005], short b[5005])
{
int t = 0, i = 1;
for (i = 1 ; i <= max(a[0], b[0]) || t > 0 ; ++ i)
{
t += (a[i] + b[i]);
a[i] = t % 10;
t /= 10;
}
a[0] = i - 1;
}
///-------------------------------------
inline void Solution()
{
for (int i = 0 ; i < GCDMAX ; ++ i)
{
for (int j = 0 ; j < GCDMAX ; ++ j)
{
x[i][j] = __gcd(i, j);
}
}
dp[0][0][0] = dp[0][0][1] = 1;
int t = 1;
for (int i = 1 ; i <= N ; ++ i, t ^= 1)
{
for (int gcd = 0; gcd < GCDMAX ; ++ gcd)
memset(dp[t][gcd], 0, sizeof(dp[t][gcd]));
for (int gcd = 0 ; gcd < GCDMAX ; ++ gcd)
{
sum(dp[t][gcd], dp[t ^ 1][gcd]);
sum(dp[t][x[gcd][v[i]]], dp[t ^ 1][gcd]);
}
}
t = N & 1;
for (int i = 0 ; i < 5005 ; ++ i)
ans[i] = dp[t][1][i];
}
///-------------------------------------
inline void Output()
{
for (int i = ans[0] ; i > 0 ; -- i) g << ans[i];
}
///-------------------------------------
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ReadInput();
Solution();
Output();
return 0;
}