Pagini recente » Cod sursa (job #2157151) | Cod sursa (job #2178298) | Cod sursa (job #3129072) | Cod sursa (job #538894) | Cod sursa (job #2665916)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("indep.in");
ofstream fout("indep.out");
vector <int> dp[2][1001];
inline int gcd(int a, int b)
{
int r;
while (b)
{
r = a%b;
a = b;
b = r;
}
return a;
}
inline void adun(vector <int> &a, vector <int> &b)
{
int i, x = 0, l = min(a.size(), b.size());
for (i = 0; i<l; i++, x = x/10)
{
x = x + a[i] + b[i];
a[i] = x%10;
}
for (i = a.size(); i < b.size(); i++, x = x/10)
{
x = x + b[i];
a.push_back(x%10);
}
for (i = b.size(); i < a.size(); i++, x = x/10)
{
x = x + a[i];
a[i] = x%10;
}
if (x)
a.push_back(x);
}
int main()
{
int x, n, i, j;
fin >> n;
dp[0][0].push_back(1);
for (i = 1; i<=n; i++)
{
fin >> x;
for (j = 0; j<=1000; j++)
dp[i&1][j] = dp[(i&1)^1][j];
for (j = 0; j<=1000; j++)
if (dp[(i&1)^1][j].empty() == 0)
adun(dp[i&1][gcd(j, x)], dp[(i&1)^1][j]);
}
if (dp[n&1][1].empty() == 0)
for (i = dp[n&1][1].size()-1; i>=0; i--)
fout << dp[n&1][1][i];
else
fout << 0;
return 0;
}