10970 - Big Chocolate

All about problems in Volume 109. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
m2lajoo
New poster
Posts: 11
Joined: Thu Jan 11, 2007 9:21 am
Location: iran

10970 - Big Chocolate

Post by m2lajoo » Wed Feb 14, 2007 8:37 pm

can you help me with this code?i don't know why it' WA

Code: Select all

var
a,b:longint;
function tedad(a,b:integer):integer;
begin
if (a=1)and(b=1) then
begin
tedad:=0;
exit;
end;
if (a=1) then
tedad:=b-1;
if (b=1) then
tedad:=a-1;
if (a<>1)and(b<>1) then
tedad:=(a-1)+tedad(1,b)*b;
end;
begin
while not eof(input) do
begin
readln(a,b);
writeln(tedad(a,b));
end;
end.

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 10970 why WA

Post by mf » Wed Feb 14, 2007 9:35 pm

m2lajoo wrote:tedad:=(a-1)+tedad(1,b)*b;
Perhaps, that should be
tedad:=(a-1)+tedad(1,b)*a;

DD
Experienced poster
Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California
Contact:

Re: 10970 - Big Chocolate

Post by DD » Mon Mar 14, 2011 12:40 am

I think this problem may be the easiest problem ever. :D
It would be much more challenging if we are allowed to stack chocolate up and cut.
Have you ever...
  • Wanted to work at best companies?
  • Struggled with interview problems that could be solved in 15 minutes?
  • Wished you could study real-world problems?
If so, you need to read Elements of Programming Interviews.

Post Reply

Return to “Volume 109 (10900-10999)”