Thursday, November 10, 2011

[UVa] 1230 - MODEX

#include <cstdio>
#include <vector>
#include <iostream>
using namespace std;
typedef long long ll;

ll sqr(ll v)
{
    return v*v;
}

ll bigMod(ll p, ll v, ll m)
{
    if (p==0) return 1;
    else if (p&1) return (v%m * bigMod(p-1,v,m))%m;
    else return (sqr(bigMod(p/2,v,m)))%m;
}

int main()
{
    int tst;
    ll x, y, n;

    cin >> tst;

    while (tst--)
    {
        cin >> x >> y >> n;
        cout << bigMod(y,x,n) << endl;
    }

    cin >> tst;

    return 0;
}

No comments:

Post a Comment

Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.

Connect Rapoo MT750S with Linux (Tested on Manjaro)

 I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...