Pagini recente » Cod sursa (job #3200750) | Cod sursa (job #3283779) | Cod sursa (job #3287938) | Cod sursa (job #1245370) | Cod sursa (job #3286329)
#include <fstream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
const int NMAX = 501, VMAX = 1001;
ifstream fin("indep.in");
ofstream fout("indep.out");
void adunare(vector<int>& A, vector<int>& B) /// A += B
{
int T = 0;
vector<int>::iterator it = B.begin();
for(vector<int>::iterator it2 = A.begin(); it2 != A.end(); ++it2)
{
if(it != B.end()) T += *(it++) + *it2;
else T += *it2;
*it2 = T % 10;
T /= 10;
}
while(it != B.end())
{
T += *(it++);
A.push_back(T % 10);
T /= 10;
}
if(T) A.push_back(T % 10);
}
void afisare(vector<int>& A)
{
for(int i = A.size() - 1; i >= 0; --i) fout << A[i];
}
vector<int> dp[VMAX + 5];
int main()
{
int n, x;
fin >> n;
dp[0].push_back(1);
while(n--)
{
fin >> x;
for(int y = 1; y < VMAX; ++y) adunare(dp[__gcd(x, y)], dp[y]);
adunare(dp[x], dp[0]);
}
afisare(dp[1]);
return 0;
}