8 years later
6 years later
Can someone tell why my code doesn’t work? For the example test cases the output is
1
18446744073709551609
22
#include <stdio.h>
#include <math.h>
size_t divsum(size_t n);
int main(void)
{
int t;
size_t n;
scanf("%d", &t);
while (t--) {
scanf("%lu", &n);
printf("%lu\n", divsum(n));
}
return 0;
}
size_t divsum(size_t n)
{
size_t sum = 1, exp, original = n;
for (size_t p = 2; p <= ceil(sqrt(original)); p++) {
exp = 0;
if (n % p == 0) {
while (n % p == 0) {
exp++;
n /= p;
}
sum *= (pow(p, exp + 1) - 1) / (p - 1);
}
}
return sum - original;
}