ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1079. Maximum

Oleg Why my program wrong anser // Problem 1079. Maximum 21 Oct 2002 09:27
var n:longint;

function sum(i:longint):longint;
begin
 if i<2 then sum:=i else
 begin
  if (i mod 2)=0
   then sum:=sum(i div 2)
   else sum:=sum(i div 2)+sum(1+(i div 2));
 end;
end;

begin
 repeat
  read(n);
  if n>0 then writeln(sum(n));
 until n=0;
end.