jzoj3520 原根
来源:互联网 发布:ipad音乐软件 方块 编辑:程序博客网 时间:2024/05/21 17:29
3520. 【NOIP2013模拟11.7B组】原根(math)
Description
Input
有且只有一个正整数m。
Output
以递增序依次输出模m的所有原根,每行输出一个原根。
Description
Input
有且只有一个正整数m。
Output
以递增序依次输出模m的所有原根,每行输出一个原根。
如果不存在模m的原根,输出-1。
分析:暴力找原根即可。
代码
var i,j,n,s:longint; fl:boolean; k:int64;function gcd(a,b:longint):longint;var r:longint;begin r:=a mod b; while r>0 do begin a:=b; b:=r; r:=a mod b; end; exit(b);end;begin assign(input,'math.in');reset(input); assign(output,'math.out');rewrite(output); readln(n); for i:=1 to n do if gcd(n,i)=1 then inc(s); if n=1 then begin writeln(1); halt; end; for i:=1 to n-1 do if gcd(n,i)=1 then begin k:=i; for j:=1 to s do begin if (k=1) then begin if j=s then begin writeln(i); fl:=true; end; break; end; k:=(k*i) mod n; end; end; if not fl then writeln(-1); close(input);close(output);end.
阅读全文
0 0
- jzoj3520 原根
- 原根
- 原根
- 原根
- 原根
- 原根
- 原根
- 原根
- 原根
- 原根
- 原根
- 原根
- 原根
- 原根
- 原根
- 原根
- 原根
- 原根
- struts2有哪些优点?
- 微风集
- tensorflow函数简介
- 关于jsp页面的复选框(checkbox)取值的获取问题
- 【Exception】Address already in use:bind;程序无法正常启动;Tomcat
- jzoj3520 原根
- yii安装详解
- bootstrap checkbox ratio 元素换行对齐的问题
- struts2是如何启动的?
- 图片选择和图片压缩
- spark-jobserver使用笔记
- kotlin项目开发总结
- 题目学习——hduoj-2136
- Jdk类库注解