fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define mod 1000000007
  5. int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
  6. int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}
  7.  
  8.  
  9.  
  10. signed main()
  11. {
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18. int t;
  19. cin>>t;
  20. while(t--)
  21. {
  22.  
  23.  
  24. int n,x,y;
  25.  
  26.  
  27. cin>>x>>y;
  28.  
  29. cin>>n;
  30. n--;
  31.  
  32. if(n%2==0)
  33. {
  34. n=n/2;
  35.  
  36. x=mul(exp(2,n),x);
  37. y=mul(exp(2,n),y);
  38. }
  39. else
  40. {
  41.  
  42. n--;
  43. n=n/2;
  44.  
  45. int x1=y-x;
  46. int y1=y+x;
  47.  
  48. x=mul(exp(2,n),x1);
  49. y=mul(exp(2,n),y1);
  50.  
  51.  
  52. }
  53.  
  54. cout<<x<<" "<<y<<endl;
  55.  
  56.  
  57.  
  58.  
  59. }
  60. }
Success #stdin #stdout 0s 4944KB
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