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 1110. Power

Help.Помогите найти ошибку
Posted by Vasurov 20 Nov 2015 01:33
var
   m, n, b, y, k, x: integer;

function St(x, n: integer): integer;
var
   i, f: integer;
begin
   f := 1;
   for i := 1 to n do
      f := f * x;
   St := f;
end;

begin
   readln(n, m, y);
   for x := 0 to m - 1 do
   begin
      b := st(x,n);
      if (b mod m) = y then
      begin
         write(x,' ');
         k := k + 1;
      end;
   end;
   if k = 0 then
      writeln(-1);
end.
Re: Help.Помогите найти ошибку
Posted by Jane Soboleva (SumNU) 20 Nov 2015 09:32
N can be as large as 999, which will clearly give overflow when you try to calculate it.
Use f:=f * x mod m; instead of f:=f * x;
(also https://en.wikipedia.org/wiki/Modular_arithmetic)