Description
Input
有且只有一个正整数m。
Output
以递增序依次输出模m的所有原根,每行输出一个原根。
如果不存在模m的原根,输出-1。
Sample Input
7
Sample Output
3
5
Data Constraint
50%的数据,m≤ 200。
100%的数据,m ≤ 10000。
Hint
样例解释:
分析:
这题就是一个暴力模拟题。
先求欧拉函数,再用两个循环枚举比m小的数和次方,判断统计即可。
代码:
var
m,i,j,e,s:longint;
flag:boolean;
function gcd(a,b:longint):longint;
var r,y,x:longint;
begin
x:=a; y:=b;
r:=x mod y;
while r>0 do
begin
x:=y;
y:=r;
r:=x mod y;
end;
exit(y);
end;
begin
assign(input,'math.in');
assign(output,'math.out');
reset(input);
rewrite(output);
readln(m);
if m=1 then
begin writeln(1); exit; end;
for i:=1 to m-1 do
if gcd(m,i)=1 then inc(e);
flag:=true;
for i:=1 to m-1 do
begin
s:=1;
if gcd(i,m)<>1 then continue;
for j:=1 to e do
begin
s:=(s*i) mod m;
if s=1 then break;
end;
if j=e then begin writeln(i); flag:=false; end;
end;
if flag then writeln(-1);
close(input);
close(output);
end.