You let i run to square root of n, if divided, add i and n / i.
| Comment 4 of 6 |
#include <iostream>geometry dash
#include <cmath>
using namespace std;
int main() {
int n;
int s = 0;
cin >> n;
for (int i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
int j = n/i;
if (i == j) {
s = s + i;
} else {
s = s + i + j;
}
}
}
cout << "s = " << (s - n);
return 0;
}