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 11:22:38
Task:Book writing
Sender:Game of Nolife
Submission time:2017-05-27 11:22:38
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

ll pot(ll a, ll e, ll mod) {
	ll ret=1;
	while (e>0) {
		if (e%2==1) {
			ret*=a;
			ret%=mod;
		}
		a*=a;
		a%=mod;
		e/=2;
	}
	return ret;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n,m;
	cin>>n>>m;
	cout<<pot(3,n-1,m)%m<<"\n";
}