Cod sursa(job #330112)

Utilizator Alexa_ioana_14Antoche Ioana Alexandra Alexa_ioana_14 Data 8 iulie 2009 19:28:13
Problema Sum Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.01 kb
#include<cstdio>
#define N 200005
#define M 8
short int *a[N];
int n,x;
void div(int x)
{
	int cx=x;
	for (int i=2; i<=x; ++i)
	{
		bool ok=false;
		while (x%i==0)
		{
			ok=true;
			x/=i;
		}
		if (ok)
			a[cx][++a[cx][0]]=i;
	}
	if (x!=1)
		a[cx][++a[cx][0]]=x;
}
void matrice()
{
	for (int i=2; i<N-4; ++i)
	{
		a[i]=new short int [M];
		a[i][0]=0;
		div(i);
	}
}
bool caut1(int n)
{
	int p=1,u=a[x][0],m;
	while (p!=u)
	{
		m=(p+u)/2;
		if (a[x][m]>=n)
			u=m;
		else
			p=m+1;
	}
	if (a[x][p]!=n)
		return 0;
	return 1;
}
bool verific(int x)
{
	for (int i=1; i<=a[x][0]; ++i)
		if (caut1(a[x][i]))
			return false;
		return true;
}
void caut()
{
	int s=1,cx=x*2;
	for (int i=2; i<=cx; ++i)
	{
		if (verific(i))
			s+=i;
	}
	printf("%d\n",s);
}
void citire()
{
	freopen("sum.in","r",stdin);
	freopen("sum.out","w",stdout);
	int t;
	scanf("%d",&t);
	while (t)
	{
		scanf("%d ",&x);
		caut();
		--t;
	}
}
int main()
{
	matrice();
	citire();
	return 0;
}