Code Submission Evaluation System Login

CSES - HIIT Open 2017

HIIT Open 2017

Contest start:2017-05-27 11:00:00
Contest end:2017-05-27 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard


History
2017-05-27 12:38:21
2017-05-27 12:35:03
Task:Book writing
Sender:Kanadan virallinen maajoukkue
Submission time:2017-05-27 12:38:21
Status:READY
Result:ACCEPTED

Show test data

Code

#include <iostream>

using namespace std;

long long MOD;

long long pmod(long long i, long long e){
    if(e==0)
        return 1%MOD;
    if(e%2==1)
        return (i * pmod(i,e-1))%MOD;
    long long asd=pmod(i,e/2);
    return (asd*asd)%MOD;
}

int main() {
    long long n;
    cin>>n>>MOD;
    cout<<pmod(3,n-1)<<endl;
    return 0;
}