fork download
  1. // Sky's the limit :)
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define int long long
  5.  
  6. /*
  7.   0: a b
  8.   1: b-a b+a
  9.   2: 2*a 2*b
  10.   3: 2*(b-a) 2*(b+a)
  11.   4: 4*a 4*b
  12.   5: 4*(b-a) 4*(b+a)
  13.   Simple implementation.
  14. */
  15.  
  16. const int MOD = 1e9 + 7;
  17.  
  18. int power(int x, int y, int m = MOD) {
  19. x %= m;
  20. int res = 1;
  21. while (y) {
  22. if (y & 1)
  23. res = res * x % m;
  24. x = x * x % m;
  25. y >>= 1;
  26. }
  27. return res;
  28. }
  29.  
  30. pair<int, int> go(int a, int b, int n) {
  31. int _a = b - a, _b = b + a;
  32. if (n & 1) {
  33. a = _a;
  34. b = _b;
  35. }
  36. int t = power(2, n / 2);
  37. int A = t * a % MOD;
  38. int B = t * b % MOD;
  39. return {A, B};
  40. }
  41.  
  42. void run_case() {
  43. int a, b, n;
  44. cin >> a >> b >> n;
  45.  
  46. auto [A, B] = go(a, b, n - 1);
  47. cout << A << ' ' << B << '\n';
  48. }
  49.  
  50. signed main() {
  51. ios_base::sync_with_stdio(false); cin.tie(nullptr);
  52.  
  53. int T = 1;
  54. cin >> T;
  55. for (int t = 1; t <= T; t++) {
  56. // cout << "Case #" << t << ": ";
  57. run_case();
  58. }
  59.  
  60. return 0;
  61. }
Success #stdin #stdout 0s 4900KB
stdin
5
1 3 5
2 3 9
3 13 28
42 999 1881
4 97 43
stdout
4 12
32 48
81920 131072
728771468 762921230
8388608 203423744