hdu1097 A hard puzzle

#include <iostream>
#include <fstream>

using namespace std;

long f(long a, long b, long m);

int main()
{
    long a, b;



    while (cin >> a >> b)
    {
        cout << f(a, b, 10) << endl;
    }
    return 0;
}

long f(long a, long b, long m)
{
    if (b == 0)
        return 1;
    else if (b & 1)
    {
        return (a % m) * f(a, b - 1, m) % m;
    }
    else
    {
        long c = f(a, b / 2, m);
        return c * c % m;
    }
}

你可能感兴趣的:(c,include)