#1933: The answer of a029 but just give me 10 robux (cheaper than Ethan) but if u don't give me i will report you to the teacher(real) this is the real answer not like ethan his is fake


1753980-3@g.puiching.edu.mo (P5A31蒲雋浠)

School : No School
ID : 2571
IP address : [192.168.120.33]
Last Login :
2025-03-20 12:13:05
a008. 盈虧互補 -- 板橋高中教學題 | From: [192.168.120.33] | Post Date : 2025-04-14 20:51

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int sumProperDivisors(int n) {
    if (n == 1) return 0;
    int sum = 1; // 1 is a proper divisor for any n > 1
    int sqrtN = sqrt(n);
    for (int i = 2; i <= sqrtN; ++i) {
        if (n % i == 0) {
            int other = n / i;
            if (i == other) {
                sum += i;
            } else {
                sum += i + other;
            }
        }
    }
    return sum;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    while (cin >> n && n != 0) {
        int sum = sumProperDivisors(n);
        if (sum == n) {
            cout << "=" << n << "\n";
        } else {
            int possibleM = sum;
            if (sumProperDivisors(possibleM) == n && possibleM != n) {
                cout << possibleM << "\n";
            } else {
                cout << "0\n";
            }
        }
    }
    return 0;
}
 
ZeroJudge Forum