加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

x^y % m 大数

发布时间:2020-12-14 03:37:14 所属栏目:大数据 来源:网络整理
导读:测试http://acm.fzu.edu.cn/problem.php?pid=1759 typedef long long LL ;LL phi(LL n){ LL s = n ; for(LL i = 2 ; i*i = n ; i++){ if(n % i == 0) s = s/i*(i-1) ; while(n % i == 0) n /= i ; } if(n != 1) s = s/n*(n-1) ; return s ;}LL Pow(LL x,LL y


测试http://acm.fzu.edu.cn/problem.php?pid=1759

typedef long long LL ;

LL   phi(LL n){
     LL s = n ;
     for(LL i = 2 ; i*i <= n ; i++){
          if(n % i == 0)  s = s/i*(i-1) ;
          while(n % i == 0) n /= i ;
     }
     if(n != 1)  s = s/n*(n-1) ;
     return s ;
}

LL  Pow(LL x,LL y,LL m){
    LL s = 1 ;
    for( ; y ; y>>= 1){
        if(y&1) { s *= x ; s %= m ;}
        x *= x ; x %= m ;
    }
    return s;
}

LL   Pow(LL x,char *y,LL m){
     LL phim = phi(m) ;
     LL s = 0  ;
     for(int i = 0 ; y[i]!= '' ; i++){
          s = s*10 + y[i] - '0' ;
          if(s >= m) break ;
     }
     if(s>=m){
          s = 0 ;
          for(int i = 0 ; y[i] != '' ; i++){
              s = s*10 + y[i] - '0' ;
              if(s >= phim) s %= phim ;
          }
          s += phim ;
          return Pow(x,s,m) ;
     }
     else return Pow(x,m) ;
}

char y[1000008] ;

int  main(){
     LL x,m  ;
     while(scanf("%I64d%s%I64d",&x,y,&m) != EOF)
          printf("%I64dn",Pow(x,m)) ;
     return 0 ;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读