#include <iostream> using namespace std; int x, sum, s, d; int main() { do { cin >> x; s = 0; for(d = 1; d * d < x; d ++) if(x % d == 0) s = s + d + x / d; if(d * d == x) s = s + d; if(s == 2 * x) sum = sum + x; } while (x != 0); cout << sum; return 0; }