IBM interview question

the mathematical problem, some coding questions