Algorithms in C++ for International Olympiad in Informatics

I’ve tried practicing code and write algorithms in C++. It’s a good language I believe that can be used in advanced algorithms.

I’ve mainly used python for analysing mathematical operations in topics like Number Theory, Cryptography, et cetra. However, I’ve tried using C++ in the last few weeks, and I would like to say that it was a good experience.

Here is a (sample) code for the sum-of-divisors function:

int sigma(int x) {
    int sum = 0;
    int v = x;
    
    while (v > 0) {
        if (x % v == 0 ) { sum += v; }
        v -= 1;
    }
    
    return sum;
}

Here is the test cases that I’ve used to produce some results:

int main() {
    int a = sigma(6);
    int b = sigma(28);
    int c = sigma(32);
    int d = sigma(123);
    
    std::cout << a << std::endl;
    std::cout << b << std::endl;
    std::cout << c << std::endl;
    std::cout << d << std::endl;
}

Results:

12
56
63
168