timus; solve "K-based Numbers" from Volume 1