Cod sursa(job #734529)

Utilizator an_drey_curentandreycurent an_drey_curent Data 14 aprilie 2012 15:06:50
Problema Suma si numarul divizorilor Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.11 kb
#include<stdio.h>
#include<bitset>
#define CMAX 1000005
#define MODP 9973 
using namespace std;
bitset<CMAX>C;
int P[CMAX/10],k = -1;
long long X;
void ciur()
{
	for(int i = 2 ; i<= CMAX-5; i++)
		if(C[i] == 0)
		{
			P[++k] = i;
			for(int j = 2; j*i <= CMAX-5; j++)
				C[j*i] = 1;
		}
}
int explog(int a,int b)
{
	int rez = 1;
	a%=MODP;
	while(b)
	{
		if(b%2==1)
			rez = (rez * a)%MODP,b--;
		a = (a * a)%MODP,b/=2;
	}
	return rez;
}
void rezolva()
{
	int a = 1,b = 1,p,nd = 1, sd =1;
	for(int i = 0 ; 1LL * P[i] * P[i] <= X && i <=k ;i++,a = 1,b = 1)
	{
		for(p = 0;X%P[i] == 0;p++,a=(a * P[i])%MODP,X/=P[i]);
		if(p!=0)
		{
			nd =(nd * (p+1)) %MODP;
			a =(a * P[i]) %MODP;
			b = explog(P[i] - 1,MODP-2);
			sd =(sd * ( ( (a - 1) * b) %MODP)) %MODP;
		}
	}
	if(X > 1)
		nd = (nd * 2)% MODP,
		sd = (sd * ((X+1)%MODP) ) %MODP;
	printf("%d %d\n",nd,sd);
}
void citire()
{
	int T;
	freopen("ssnd.in","r",stdin);
	freopen("ssnd.out","w",stdout);
	scanf("%d",&T);
	while(T--)
	{
		scanf("%lld",&X);
		rezolva();
	}

}
int main()
{
	ciur();
	citire();
	return 0;
}