Programming contests

20 Programming Exercise for Beginners

January 1, 2019 12:00 AM – December 31, 2019 12:00 AM

Finding numbers divisible by 12 and 21

Create a program that enumerates the first 100 positive numbers that can be divided both by 12 and by 21 in ascending order.

Output Specification

The output consists of 100 lines containing the numbers. Each line, including the last one, must be terminated by a newline character.

Hints and Guide

The exercise can easily be solved with one iteration. The iteration starts with the number 1 and runs until the necessary amount of output is constructed. The iteration can use two integers: one for counting the lines in the output and one for the next value under investigation. The % operator helps us find the divisors by calculating the remainder: a % b is 0 only if b is a divisor of a.

One possible solution is available in: main.c.

Possible Improvements

In programming contests where the execution time is crucial, a widely used technique is to store the constant output of the application (for example in an array) to avoid the delay caused by the calculation. We can apply this trick in our scenario since we need to store only 100 integer.

Acknowledgement This work was supported by the construction EFOP-3.4.3-16-2016-00021. The project was supported by the European Union, co-financed by the European Social Fund.
University of Debrecen; Faculty of Informatics; v. 03/01/2019