Advertisement
Saleh127

UVA 12898/ uvaLive 6918

Jun 29th, 2021
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10.  
  11. test
  12. {
  13. ll n,m,i,j,k,l;
  14.  
  15. cin>>n>>m;
  16.  
  17. ll a[69],b[69];
  18.  
  19. memset(a,0,sizeof a);
  20. memset(b,0,sizeof b);
  21.  
  22. i=0;
  23. while(n>0)
  24. {
  25. a[i]=n%2;
  26. n/=2;
  27. i++;
  28. }
  29.  
  30. i=0;
  31. while(m>0)
  32. {
  33. b[i]=m%2;
  34. m/=2;
  35. i++;
  36. }
  37.  
  38. ll oor[69];
  39. ll aand[69];
  40.  
  41. memset(oor,0,sizeof oor);
  42. memset(aand,0,sizeof aand);
  43.  
  44. for(i=63;i>=0;i--)
  45. {
  46. if(a[i]==b[i])
  47. {
  48. oor[i]=a[i];
  49. aand[i]=a[i];
  50. }
  51. else
  52. {
  53. for(j=i;j>=0;j--)
  54. {
  55. oor[j]=1;
  56. aand[j]=0;
  57. }
  58. break;
  59. }
  60. }
  61. ll p[65];
  62. memset(p,0,sizeof p);
  63.  
  64. for(i=0;i<64;i++) p[i]=pow(2,i);
  65.  
  66. ll orr=0,andd=0;
  67.  
  68. for(i=0;i<64;i++)
  69. {
  70. orr+=(p[i]*oor[i]);
  71. andd+=(p[i]*aand[i]);
  72. }
  73.  
  74. cout<<"Case "<<cs<<": "<<orr<<" "<<andd<<endl;
  75. }
  76.  
  77.  
  78. return 0;
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement