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

luogu 5091 欧拉定理

发布时间:2020-12-16 09:16:22 所属栏目:百科 来源:网络整理
导读:? ? 裸题: 扩展欧拉定理的应用? 1 #includebits/stdc++.h 2 using namespace std; 3 int ph( int x){ 4 int ret= x; 5 for ( int i= 2 ;i*i=x;i++ ) 6 if (x%i== 0 ){ 7 ret=ret/i*(i- 1 ); 8 while (x%i== 0 ) x/= i; 9 } 10 if (x 1 ) ret=ret/x*(x- 1 );

?

?

裸题: 扩展欧拉定理的应用?

 1 #include<bits/stdc++.h>
 2 using namespace std; 
 3 int ph(int x){
 4     int ret=x;  
 5     for(int i=2;i*i<=x;i++)
 6         if(x%i==0){
 7             ret=ret/i*(i-1);    
 8             while (x%i==0) x/=i;  
 9         }
10     if(x>1) ret=ret/x*(x-1);     
11     return ret;  
12 }  
13 int main(){
14     int a,b=0,m,check=0;  
15     scanf("%d%d",&a,&m);  
16     int t=ph(m); 
17     char c;  
18     while ((c=getchar()) && !isdigit(c));  
19     while (isdigit(c)){
20         b=b*10+(c^48);  
21         while (b>=t) b-=t,check=1;    
22         c=getchar();    
23     } 
24     if(check) b=b+t;   
25     int ans=1;  
26     for(int i=0;i<=20;i++){
27         if(b&(1<<i)) ans=1LL*ans*a%m;  
28         a=1LL*a*a%m; 
29     }
30     printf("%dn",ans);  
31     return 0; 
32 }
View Code

(编辑:李大同)

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

    推荐文章
      热点阅读