Cod sursa(job #2199926)

Utilizator Dobricean_IoanDobricean Ionut Dobricean_Ioan Data 29 aprilie 2018 18:02:29
Problema Indep Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.32 kb
#include <fstream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
ifstream fin ("indep.in");
ofstream fout ("indep.out");
 
class Big{
    enum { MAX = 30 };
    short x[MAX];
    int n;
public:
    Big(int nr = 0);
    short& 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)
{
    for ( int i = ob.n; i >= 1; --i )
        os << ob.x[i];
    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 /= 10)
        c[i] = (t += a[i] + b[i]) % 10;
    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 /= 10)
        c[i] = (t += a[i] * b) % 10;
    c.n = i - 1;
    return c;
}
 
Big::Big(int nr) {
    memset(x, 0, sizeof(x)); n = 0; 
    while ( nr ) {
        x[++n] = nr % 10; nr /= 10;
    }
}