Perfect numbers: Difference between revisions

Content added Content deleted
Line 230: Line 230:
}
}
int max = cast(int) sqrt(cast(real) n) + 1;
int max = cast(int) sqrt(cast(real) n) + 1;
int tot = 1;
int sum = 1;
for (int i = 2; i < max; i++) {
for (int i = 2; i < max; i++) {
if (n % i == 0) {
if (n % i == 0) {
tot += i;
sum += i;
int q = n / i;
int q = n / i;
if (q > i) {
if (q > i) {
tot += q;
sum += q;
}
}
}
}
}
}
return tot == n;
return sum == n;
}
}