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:07:02
2017-05-27 11:29:38
Task:Book writing
Sender:Ace of Spades
Submission time:2017-05-27 12:07:02
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll n,m;
    cin>>n>>m;
    ll ans = 1;
    --n;
    ll q = 3;
    for(;n; n/=2) {
	if(n&1) {
	    ans = ans*q%m;
	}
	q = q*q%m;
    }
    cout<<ans%m<<'\n';
}