Editorial for COCI '22 Contest 2 #2 Ekspert


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.

Suppose y<x. The product xy can be represented as the sum of at most log2y numbers. We can do that in the following way:

xy=2ix for each i where the ith position in the binary representation of y is 1.

For example: 1413=2014+2214+2314

Such a solution uses at most 2log2y operations: log2y for storing the result in a register, and log2y for auxiliary operations.


Comments

There are no comments at the moment.