-
Notifications
You must be signed in to change notification settings - Fork 0
/
B_aliceandbob.cpp
54 lines (43 loc) · 763 Bytes
/
B_aliceandbob.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll power( ll a, ll b, ll mod){
ll res = 1;
while(b){
if(b&1){
res = (res*a)%mod;
}
a = (a*a)%mod;
b >>= 1;
}
return res;
}
void solve()
{
ll x, y, k;
cin>>x>>y>>k;
ll mod = x+y;
x = (x*power(2LL, k, mod))%mod;
y = mod - x;
cout<<min(x, y);
}
int main()
{
ios_base::sync_with_stdio(false) ;
cin.tie(NULL);
cout.tie(NULL) ;
#ifndef ONLINE_JUDGE
//for getting input from input.txt
freopen("inputA.txt","r",stdin);
//for getting output from output.txt
freopen("outputA.txt","w",stdout);
#endif
int t = 1 ;
cin>>t;
while( t-- )
{
solve();
cout<<"\n";
}
return 0 ;
}