Cod sursa(job #634356)

Utilizator ContraPunctContrapunct ContraPunct Data 16 noiembrie 2011 01:06:11
Problema Suma si numarul divizorilor Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.64 kb
#include<fstream>
const long long Nmax = 1000006;
const int MOD = 9973;
using namespace std;

char ciur[Nmax];
long long nn;
long long n;
ifstream fin("ssnd.in");
ofstream fout("ssnd.out");

void Ciur ()
{
	long long i = 0 ,j = 0;
	for(i=4; i<=nn; i+=2)
		ciur[i]='1';

	for(i=3; i<=nn; i+=2)
		if(ciur[i] == 0 ) 
		{
			j = i*i;
			for( ; j<=nn; j += (i+i))
				if(ciur[j] == 0)
					ciur[j]='1';
		}
}

long long t[1003];

void ReadData()
{
	fin>>n;
	for( int i=0;i<n;i++)
	{
		fin>>t[i];
		if( nn < t[i])
			nn = t[i];
	}
}

void Sol()
{
	int i,j;
	int x,aux;
	int nr_div;
	int putere;
	for( i = 0; i<n; i++)
	{
		int nr=1;
		int suma=1;
		x = t[i];
		j=2;
		aux = x;
		if( ciur[aux] == 0) 
		{
			nr = 2;
			suma = aux+1;
		}
		else
		{
			if( aux % j == 0 )
			{
				nr_div = 0;
				putere = 1;
				while( aux % j == 0)
				{
					putere *= j;
					nr_div ++ ;
					putere = putere % MOD;
					aux = aux /j;
				}
				suma = suma * ((putere * j  - 1) / (j-1));
				suma = suma % MOD;
				nr = nr * (nr_div + 1);
			}
			for( j = 3; j*j <= x; j += 2)
			{
				if( ciur[j] == 0)
				{
					aux = x;
					if( aux % j == 0 )
					{
						nr_div = 0;
						putere = 1;
						while( aux % j == 0)
						{
							putere *= j;
							putere = putere % MOD;
							nr_div ++ ;
							aux = aux /j;
						}	
					putere = putere % MOD;
					suma = suma * ((putere * j  - 1) / (j-1));
					suma = suma % MOD;
					nr = nr * (nr_div + 1);
					}
				}
			}
		}
		fout<<nr<<" "<<suma<<"\n";
	}
}

int main()
{
	ReadData();
	Ciur();
	Sol();
	fout.close();
	fin.close();
	return 0;
}