import "std/io";

fun check_perfect_number(n: int64) -> unit {
    let sum: int64 = sum_of_divisors(n, n - 1, 0);
    if n == sum {
        print(sum as string);
    }
    return;
}

fun main() {
    test_numbers(500);
}

fun sum_of_divisors(n: int64, divisor: int64, sum: int64) -> int64 {
    if divisor == 0 {
        return sum;
    }
    let mod_res: int64 = n % divisor;
    if mod_res == 0 {
        return sum_of_divisors(n, divisor - 1, sum + divisor);
    }
    return sum_of_divisors(n, divisor - 1, sum);
}

fun test_numbers(n: int64) {
    if n == 0 {
        return;
    }
    check_perfect_number(n);
    test_numbers(n - 1); // Return dummy value from recursive call
}
