ICS-E4020: Prerequisite test

Abundant numbers

Write a program that prints the first N abundant numbers. The program has to be a command-line tool that you can run as follows on the classroom Linux computers:

    ./abundant N

It has to print the first N abundant numbers to STDOUT, one number per line (and nothing else!), and then exit successfully. You can assume that the value N is a positive integer at most 1000000.


Your program has to be written in standard C++, using the standard version C++11. Your program can use all functions in the C++ standard library (including all functions in the C standard library), but no other libraries. It is fine to use plain C, as long as your program compiles fine with a C++ compiler. Your program has to be written 100% by yourself. You cannot work together with other students, or use any code that you find online.

Your solution has to be a single C++ file, named abundant.cc, and it has to compile fine with GCC version 4.8, which is installed in the classroom computers. Test your code on the classroom computers and make sure the following command compiles it successfully:

    g++-4.8 -std=c++11 -Wall -Wextra -O3 abundant.cc -o abundant

Then make sure it works correctly (here “$” represents the Linux command prompt); here are some examples:

    $ ./abundant 1
    $ ./abundant 2
    $ ./abundant 5
    $ ./abundant 10000 | tail -1
    $ ./abundant 5 | md5sum
    f85c2aa82cd806cb71bcec038fe5a4c5  -
    $ ./abundant 10000 | md5sum
    9063302ee3b8bb6ab5d3a4cbf64c17f7  -

The performance does not matter; a slow but correct solution is sufficient.

Submitting your solution

You will submit your solution online, using this form. The submission form is open from Monday, 4 April, at noon, until Friday, 15 April, at noon.

The form asks you to enter the following information:

If all goes well, you should eventually receive an invitation by email from GitHub to join the course organization. After that, read the instructions on the GitHub workflow to get started with the course work.