51nod 1135 原根 就是原根...
来源:互联网 发布:淘宝福兴隆珠宝是假的 编辑:程序博客网 时间:2024/06/08 10:46
%%% dalao Orz ,筛素数到sqrt(n),分解
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>#define N 100000#define LL long longusing namespace std;LL prime[100010],tot,cnt,p[100010],n;bool bo[100010],flag;void init(){ for(int i=2;i<=N;i++){ if(!bo[i])prime[++tot]=i; for(int j=1;j<=tot&&i*prime[j]<=N;j++){ bo[i*prime[j]]=1; if(i%prime[j]==0)break; } }}void divide(int x){ cnt=0; for(int i=1;prime[i]*prime[i]<=x;i++){ if(x%prime[i]==0){ p[++cnt]=prime[i]; while(x%prime[i]==0)x/=prime[i]; } } p[++cnt]=x;}LL qpm(LL x,LL y,LL z){ LL ans=1; while(y){ if(y&1) ans=(ans*x)%z; x=(x*x)%z;y>>=1; } return ans;}int main(){ scanf("%lld",&n); init(); divide(n-1); for(int i=2;i<n;i++){ flag=0; for(int j=1;j<=cnt;j++){ LL tmp=(n-1)/p[j]; if(qpm(i,tmp,n)==1){flag=1;break;} } if(!flag){printf("%d\n",i);break;} } return 0;}
阅读全文
0 0
- 51nod 1135 原根 就是原根...
- 51nod 1135 原根
- 51nod 1135 原根
- 【51nod 1135 原根】
- 51nod-1135:原根
- 51nod 1135 原根
- 51nod 1135 原根
- 51nod 1135 原根
- 51nod 1135 原根
- 51 Nod 1135 原根
- 51 NOD 1135 原根
- 51nod 1135原根
- 51Nod 1135 原根
- 51nod 1135 原根
- 51nod 1135 原根
- 51Nod-1135-原根
- 51nod 1135 原根
- 51Nod 1135 原根
- Activiti支持的数据库
- POJ
- CDH大数据平台实施经验总结
- jQuery文档处理
- 【最长上升子序列 && 输出路径】HDU
- 51nod 1135 原根 就是原根...
- spring特性学习
- 第四章 第七节: 连接
- 转:Spark SQL中Join常用3种实现
- 十二、基础数据-版权信息(credits)
- XAMPP错误: Apache shutdown unexpectedly解决办法
- Android(3):编辑使用点9图和设置字体颜色
- 网易编程笔试题(一):合唱团
- 简单的滚动切换