Editorial for COCI '13 Contest 1 #5 Organizator
Submitting an official solution before solving the problem yourself is a bannable offence.
Notice that the solution equals the size of a team multiplied by the number of participating clubs, while a club participates if it has a member count divisible by the team size.
The easiest method to count the participating clubs for some team size  is iterating over all club sizes and counting clubs that have a size divisible by 
. The complexity of this algorithm is 
, where 
 is the maximum club size, because the team size can be any value between 
 and 
, and counting for each team size takes 
.
We need a faster method of counting the competing clubs. Since club sizes are limited to  million, we can use an array 
 of size 
 to store, for each possible size, the number of clubs with that size.
In order to count the participating clubs for some team size , we need to compute the sum: 
, which requires 
 steps.
Trying out all possibilities for  from 
 to 
 requires 
 steps, which approximately equals 
. Thus, the complexity of this algorithm is 
, which is sufficient to score all points.
Comments