static int cmmdc(int a, int b)
{
if (b == 0) return a;
else return cmmdc(b, a % b);
}
static int xlan(int x, int n)
{
if (n == 0) return 1;
else return x * xlan(x, n - 1);
}
static void putere(int n, out int x, out int k)
{
//calculam in k cmmdc al exponentilor din
//descompunerea in factori primi
k = 0;
int d = 2,m=n;
while(n>1)
{
if (n % d == 0)
{
int e = 0;
while (n % d == 0) { e++; n = n / d; }
k = cmmdc(k, e);
}
else d++;
if(n>1 && d*d>n) { k = 1; break; }
}
//calculam pe x la produs de factori primi la
//puterea impartita la k
d = 2;
n = m;
if(k==1) { x = n; return; }
x = 1;
while (n > 1)
{
if (n % d == 0)
{
int e = 0;
while (n % d == 0) { e++; n = n / d; }
x = x * xlan(d, e / k);
}
else d++;
}
}
|