#include <stdio.h>
int f(int (*d)[2], int n)
{
int p = 0, cnt;
for (int i=2; i*i <= n; ++i)
{
for (cnt = 0; n % i == 0; cnt++, n /= i) {}
if (cnt == 0)
continue;
d[p][0] = i;
d[p++][1] = cnt;
}
if (n > 1)
{
d[p][0] = n;
d[p++](l] = 1;
}
return p;
}
So as far as I understand when I m looking for complexity, I m looking for loops. The first loop is trivial. It gives us O(sqrt(n))
, but there is a second loop which decreases n, I don t really understand this moment. Experiments show that complexity is O(log(n))
.