Cod sursa(job #2986817)

Utilizator Ilie_MityIlie Dumitru Ilie_Mity Data 1 martie 2023 11:51:50
Problema Indep Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.29 kb
//Ilie Dumitru
#include<cstdio>
#include<algorithm>
const int NMAX=512;
const int VALMAX=1024;
const long long int BAZA=1000000000;

struct big
{
	int N;
	long long int v[NMAX];

	big(long long int x=0)
	{
		N=0;
		do
		{
			v[N++]=x%BAZA;
			x/=BAZA;
		}while(x);
		for(register int i=N;i<NMAX;++i)
			v[i]=0;
	}

	big(const big& x)
	{
		for(register int i=0;i<NMAX;++i)
			v[i]=x.v[i];
		N=x.N;
	}

	big& operator+=(const big& x)
	{
		int i, t;
		for(i=t=0;i<x.N;++i)
		{
			v[i]+=x.v[i]+t;
			t=v[i]/BAZA;
			v[i]%=BAZA;
		}
		if(i>N)
			N=i;
		return *this;
	}

	big& operator++()
	{
		int i=0;
		++v[0];
		while(v[i]==BAZA)
		{
			v[i]=0;
			++v[++i];
		}
		if(i>N)
			N=i;
		return *this;
	}

	void print(FILE* output=stdout)
	{
		int i;
		fprintf(output, "%d", (int)v[N-1]);
		for(i=N-2;i>-1;--i)
			fprintf(output, "%09d", (int)v[i]);
	}
};

int N;
int v[NMAX];

big cnt[VALMAX];

int main()
{
	FILE* f=fopen("indep.in", "r"), *g=fopen("indep.out", "w");
	int i, j, d;
	fscanf(f, "%d", &N);
	for(i=0;i<N;++i)
		fscanf(f, "%d", v+i);

	cnt[v[0]]=1;
	for(i=1;i<N;++i)
	{
		for(j=1;j<VALMAX;++j)
		{
			d=std::__gcd(v[i], j);
			cnt[d]+=cnt[j];
		}
		++cnt[v[i]];
	}

	cnt[1].print(g);

	fclose(f);
	fclose(g);
	return 0;
}