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 Linux:

    ./abundant N

It has to print the first N abundant numbers to STDOUT, one number per line. Example:

    $ ./abundant 5
    12
    18
    20
    24
    30

You can assume that the value N is a positive integer at most 1000000.

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

Rules

Your program has to be written in standard C or C++. You can use the standard versions C++11 and C11, or any previous version.

Your program can use any functions in the C or C++ standard library, but no other libraries. It has to be written 100% by yourself. You cannot work together with other students, or use any code that you find online.

Your program should compile fine with GCC version 4.8 or 4.9. For example, if you have written a C++ program using C++11, I would expect that the following command on the classroom Linux computers will compile your program successfully:

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

Submitting your solution

Your solution should be a single C or C++ file, named abundant.c or abundant.cc. Email your solution to the teaching assistant as instructed here.