模算术运算,加、减、乘、幂运算

#include
#define ll long long
#define MOD 10000007

ll mod_add(ll x, ll y){
	return (x%MOD + y%MOD) % MOD;
}

ll mod_sub(ll x, ll y){
	return ((x - y) % MOD + MOD) % MOD;
}

ll mod_mul(ll a, ll b, ll N)
{
    ll ret = 0;
    while (b)
    {
        if (b & 1)
            ret = (ret + a) % N;
        a = 2 * a % N;
        b >>= 1;
    }
    return ret;
}

ll mod_pow(ll x, ll n, ll N)                //x^n % N
{
    ll ret = 1;
    x %= N;
    while (n)
    {
        if (n & 1)
            ret = mod_mul(ret, x, N);
        x = mod_mul(x, x, N);
        n >>= 1;
    }
    return ret;
}

int main(){
	ll x, y;
	scanf("%lld%lld",&x,&y);
	printf("%lld %lld %lld %lld\n",mod_add(x,y),mod_sub(x,y),mod_mul(x,y,MOD),mod_pow(x,y,MOD));
	return 0;
}

你可能感兴趣的:(常用模板)