1 해설

  • 1
    @ 2025-1-16 11:45:08
    #include <bits/stdc++.h>
    using namespace std;
    /*
    (a+b)%k = (a%k+b%k)%k
    (a*b)%k = ((a%k)*(b%k))%k 
    */
    
    //快速幂  (a^x)%p
    // a=1231321313
    // x=5464646546
    // p=12313 
    
    long long a,x,p;
    
    long long f(int k){//a的k次方 %p的结果 
    	if(k==0) return 1;
    	if(k==1) return a%p;
    	long long tmp=f(k/2);
    	if(k%2==0){
    		return tmp*tmp%p;
    	}else{
    		return (tmp*tmp%p)*a%p;
    	}
    }
    
    int main(){
    	cin>>a>>x>>p;
        cout<<f(x);
        return 0;
    }
    
    • 1

    정보

    ID
    13
    시간
    1000ms
    메모리
    256MiB
    난이도
    10
    태그
    제출 기록
    2
    맞았습니다.
    1
    아이디