Cod sursă (job #813742)

Utilizator avatar patricksavin Savin Patrick Alexandru patricksavin IP ascuns
Problemă 2sah (clasele 11-12) Compilator cpp-32 | 0,98 kb
Rundă Arhiva de probleme Status evaluat
Dată 11 mar. 2025 13:59:53 Scor 30
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("2sah.in");
ofstream fout("2sah.out");
#define cin fin
#define cout fout
long long n,k,m;
long long power(long long base, long long exp, long long mod) {
    long long result = 1;
    base = base % mod;  // Incepem prin a face base modulo mod
    while (exp > 0) {
        if (exp % 2 == 1) {
            result = (result * base) % mod;
        }
        base = (base * base) % mod;
        exp = exp / 2;
    }
    return result;
}
#define mod 100003
int main()
{
    int c;
    cin >> c;
    cin >> n >> k;
    m=2*n+1;
    n++;
    if(c==1)
    {
        if (k == 1) {
            cout << "1";
        } else if (k == 2) {
            cout << "3";
        } else if (k == 3) {
            cout << "9";
        } else if (k == 4) {
            cout << "27";
        } else {
            long long result = power(3, k - 1, mod);
            cout << result;
        }
    }
    return 0;
}