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 13:04:28
2017-05-27 11:29:15
Task:Book writing
Sender:kyy-kol
Submission time:2017-05-27 13:04:28
Status:READY
Result:ACCEPTED

Show test data

Code

#include <iostream>

using namespace std;
long pow(long b, long p, long mod) {
    if (p == 1) return b%mod;
    if (p == 0) return 1%mod;
    if (p%2 == 0) {
        long t = pow(b, p/2, mod);
        return (t*t)%mod;
    } else return (pow(b, p-1, mod)*b)%mod;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    long a, b;
    cin >> a >> b;
    cout << pow(3, a-1, b) << endl;
}