Advertisement
ainem

sample

May 22nd, 2022
763
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int Mod = 1e9 + 7;
  4. long long binpow(long long a, long long b, long long m) {
  5.     a %= m;
  6.     long long res = 1;
  7.     while (b > 0) {
  8.         if (b & 1)
  9.             res = res * a % m;
  10.         a = a * a % m;
  11.         b >>= 1;
  12.     }
  13.     return res;
  14. }
  15. int main() {
  16.     cin.tie(0)->sync_with_stdio(false);
  17.     long long a, b, n;
  18.     cin >> a >> b >> n;
  19.  
  20.     long long p = binpow(a, n, Mod);
  21.     long long q = binpow(b, n, Mod);
  22.     long long sum = (p + q) % Mod;
  23.     long long dif = abs(a - b);
  24.     cout << __gcd(sum, dif);
  25.     return 0;
  26. }
Advertisement
RAW Paste Data Copied
Advertisement