Editorial for WC '15 Contest 4 J1 - Telling Time


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Given a positive integer G and a list of N other positive integers, this question asks to find the number of integers in the list which are multiples of G. The solution is to just loop through the list and check if each integer is a multiple of G. If so, increment a running counter variable.

Checking if a number F is a multiple of G can be done with the modulo (or remainder) operator in most programming languages (the % operator in C++/Java/Python, for instance). That is, F is a multiple of G if and only if F \mathbin{\%} G is equal to 0. Since we loop through an array of size N, this runs in \mathcal O(N).


Comments

There are no comments at the moment.