# Cod sursa(job #1612594)

Utilizator Data 24 februarie 2016 22:27:42 Suma si numarul divizorilor 10 cpp done Arhiva educationala 1.48 kb
``````#include <stdio.h>
#include<vector>
#include<math.h>
#define PRIM 1000001
#define SQprim 1001
#define esteprim(i) P[i]==false
#define LL long long
using namespace std;
bool P[PRIM];
LL n,m,i,t,j,x,ok,SQ,SUM,PROD,p,P1,P2;
LL putere (LL x, LL y)
{
if (y==0)
return 1;
return putere(x,y-1)*x;
}
int main()
{
freopen ("ssnd.in","r",stdin);
freopen ("ssnd.out","w",stdout);
scanf ("%lld",&t);
vector <LL> V;
for (i=2;i<SQprim;i++)
if (esteprim(i))
{
V.push_back(i);
for (j=i*2;j<PRIM;j+=i)
P[j]=true;
}
for (i=SQprim;i<PRIM;i++)
if (esteprim(i))
V.push_back(i);
for (;t>0;t--)
{
scanf ("%lld",&x);
ok=0;
SQ=sqrt(x);
PROD=1;
SUM=1;
P1=P2=1;
for (i=0;V[i]<=PRIM&&V[i]<=x;i++)
if (x%V[i]==0)
{
ok=1;
p=0;
j=V[i];
while (x%j==0)
{
p++;
x/=j;
}
PROD*=p+1;
P1*=(putere(j,p+1)-1);
P2*=j-1;

}
if (ok)
{
SUM=P1/P2;
printf ("%lld %lld\n",PROD,SUM);
}
else
if (x==1)
printf ("1 1\n");
else
printf ("2 %lld\n",x+1);
}
return 0;
}
``````