IOM 2016, Блиц — Задача 53

Olympiad of Metropolises, Moscow. Blitz Contest, September, 5 · 5 септември 2016 г.

Условие

What is the output of following code for foo(5)?

Java listing of class test with a field int x=0 and a method public int foo(int n): it sets int a = 0 and increments x; if n == 1 it sets a = 1 and prints x with System.out.println; else if n%2 == 0 it sets a = foo(n/2); else a = foo(2*n + 2); it returns a.

Решение

Внимание: Непълно решение

В архива няма официално решение на тази задача.


Оригинал в Архива: blitz.pdf