zoukankan      html  css  js  c++  java
  • 51nod 1135 原根

    传送门

    题目

    //Achen
    #include<algorithm>
    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<cstdio>
    #include<vector>
    #include<queue>
    #include<ctime>
    #include<cmath> 
    typedef long long LL;
    using namespace std;
    int p,d[100],mod;
    
    template<typename T> void read(T &x) {
        char ch=getchar(); x=0; T f=1;
        while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
        if(ch=='-') f=-1,ch=getchar();
        for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
    }
    
    LL ksm(LL a,LL b) {
        LL base=a,res=1;
        while(b) {
            if(b&1) (res*=base)%=mod;
            (base*=base)%=mod;
            b>>=1;
        }
        return res;
    }
    
    int main() {
    #ifdef DEBUG
        freopen(".in","r",stdin);
        freopen(".out","w",stdout);
    #endif
        read(p); 
        mod=p; p--;
        int nn=sqrt(p),tp=p;
        for(int i=2;i<=nn;i++) 
            if(tp%i==0) {
                d[++d[0]]=i;
                while(tp%i) 
                    tp/=i;
            }
        if(tp!=1) d[++d[0]]=tp;
        for(int i=2;i<=p;i++) {
            int fl=1;     
            for(int j=1;j<=d[0];j++) {
                if(ksm(i,p/d[j])==1) {
                    fl=0;
                    break;
                }
            }
            if(fl) {
                printf("%d
    ",i); 
                break;
            }
        }
        return 0;
    }
    View Code
  • 相关阅读:
    111111
    国际化(提取代码中文)
    分库操作(无事务)
    Nignx(四)location语法详解
    Nginx项目笔记
    SAX:进行XML解析
    流处理PDF、Base64
    JAVA8:stream流
    JPA一对多,多对一映射
    有关技术站点
  • 原文地址:https://www.cnblogs.com/Achenchen/p/8079110.html
Copyright © 2011-2022 走看看