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 1012. K-based Numbers. Version 2

This can't be wrong,why???
Posted by zeratul 3 Jul 2003 17:46
program xc1;
 var i:integer;
  a0,a1,a2:longint;
  n,k:integer;
begin
 read(n,k);
 a0:=1;
 a1:=k-1;
 for i:=2 to n do
 begin
  a2:=(k-1)*(a0+a1);
  a0:=a1;
  a1:=a2;
 end;
 writeln(a2);
end.
Re: This can't be wrong,why???
Posted by Evil Cheater 5 Jul 2003 08:40
 Your logic seems OK (I didn't check it, but it seems). Your problem
is that the numbers might (and will) be bigger than a longint (not in
the input but in the output).
Re: This can't be wrong,why???
Posted by lz 6 Jul 2003 12:16
number 1009 you must use int64
number 1012 you must use your own count arithmatic