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 14:41:52
2017-05-27 14:24:49
2017-05-27 13:15:45
2017-05-27 13:10:25
Task:Book writing
Sender:oispa opiskelupaikka tefyllä ;...;
Submission time:2017-05-27 14:41:52
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>

using namespace std;
long long n, m;

long long powasdas(long long b, long long e){
    if(e == 0)
        return 1;
    //cout << "taalla fak" << endl;
    long long lol = powasdas(b, e/2);
    lol = (lol*lol)%m;
    if(e%2 == 1){
        lol*=b;
        lol%=m;
    }
    //cout << b << " ^ " << e <<  " = " << lol << endl;
    return lol;
}

long long wtf(long long j){
    long long ans = 1;
    for(long long i = 0; i < j; ++i){
        ans+=2*wtf(i);
    }
    return ans;
}
int main(){
    
    cin >> n >> m;
    long long lol = (powasdas(3, n-1))%m;
    lol = (lol)%m;
    cout << lol << endl;
    //cout << wtf(n) << endl;
    return 0;
}