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

WA on 4th. Can help? If ((a mod c)*(b mod c)) mod c = a*b mod c?
Posted by Koryakov Anton_ghost_Anigus 9 Jan 2006 22:31
program power_1110_cod2;

{$APPTYPE CONSOLE}
var n,m,y:integer;
cou:integer;
met,met2:boolean;


function modalus(mx,mn,mm:integer):integer;
var mcou:integer;
mmn:integer;
begin
mmn:=1;
for mcou:=1 to mn do
begin
mmn:=mmn*(mx mod mm);
end;
modalus:=mmn mod mm;
end;

begin
readln(n,m,y);
if y=0 then
begin
write(0);
met2:=true;
met:=true;
end else met2:=false;

for cou:=1 to m-1 do
if modalus(cou,n,m)=y then
begin
if met2=true then
begin
write(' ');
write(cou);
met:=true;
end else
begin
write(cou);
met:=true;
met2:=true;
end;
end;
if met=false then writeln(-1) else
writeln;
end.