Pagini recente » Cod sursa (job #1281931) | Cod sursa (job #1800529) | Cod sursa (job #204790) | Cod sursa (job #1378639) | Cod sursa (job #2199940)
#include <fstream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
ifstream fin ("indep.in");
ofstream fout ("indep.out");
const int Base = 1.e6;
class Big{
enum { MAX = 105 };
int x[MAX];
int n;
public:
Big(int nr = 0);
int& operator [] (int i) { return x[i]; }
friend Big operator * (Big A, int B);
friend Big operator + (Big o1, Big o2);
friend ostream& operator << (ostream& os, const Big& ob);
};
const int Dim = 1001;
Big D[Dim];
int n;
int main() {
fin >> n;
int x;
Big unu = 1;
for( int i = 1; i <= n; ++i) {
fin >> x;
for ( int j = 1; j < Dim; ++j)
D[__gcd(x,j)] = D[__gcd(x,j)] + D[j];
D[x] = D[x] + unu;
}
fout << D[1];
}
ostream& operator << (ostream& os, const Big& ob)
{
os << ob.x[ob.n];
for ( int i = ob.n - 1; i >= 1; --i )
os << ob.x[i] / Base;
return os;
}
Big operator + (Big a, Big b)
{
Big c; int i, t = 0;
for (i = 1; i <= a.n or i <= b.n or t; ++i, t /= Base)
c[i] = (t += a[i] + b[i]) % Base;
c.n = i - 1;
return c;
}
Big operator * (Big a, int b)
{
Big c; int i, t = 0;
if ( b == 0 ) return c;
for (i = 1; i <= a.n or t; ++i, t /= Base)
c[i] = (t += a[i] * b) % Base;
c.n = i - 1;
return c;
}
Big::Big(int nr) {
memset(x, 0, sizeof(x)); n = 0;
while ( nr ) {
x[++n] = nr % Base; nr /= Base ;
}
}