Pergunta de entrevista da empresa Yandex

How would you solve (~div 3) problem?