Yandex interview question

How would you solve (~div 3) problem?