Problem S.141 (Mathematical and Physical Journal for High Schools, Problem S.141.). See details here: https://www.komal.hu/feladat?a=feladat&f=S141&l=hu This program can be run in C++.