这是一个求最大公约数的题目:给定整数a,b,n,求an+bn和a-b的最大公约数(答案对1e9+7取模)
(1<=a,b,n<=10^18)
纯快速幂,WA70,无TLE
#include <bits/stdc++.h>
#pragma GCC optimize(2) //优化
using namespace std;
#define int unsigned long long
#define mod 1000000007
int n, m, k;
int ret;
int quickPower(int a, int b) {
int ans = 1, base = a;
while (b > 0) {
if (b & 1)
ans *= base;
base *= base;
b >>= 1;
}
return ans;
}
void input() { cin >> n >> m >> k; }
void solve() {
int minus = n - m;
int ans = quickPower(n, k) + quickPower(m, k);
ret = (__gcd(ans, minus)) % mod;
return;
}
void output() { cout << ret; }
void FastIO() { //优化
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
signed main() {
FastIO();
input();
solve();
output();
return 0;
}
码风很丑,见谅