fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int n;cin>>n;
  7. while(n--){
  8. int c,b;
  9. cin>>c>>b;
  10. int cnt=0;
  11. if((c/b)<=1) {
  12. cout<<c<<endl;
  13. continue;
  14.  
  15. }
  16. int res=c/b;
  17. while(res){
  18. if(res&1) cnt++;
  19. res=res>>1;
  20. }
  21. cout<<cnt*b<<endl
  22. ;
  23. }
  24. return 0;
  25. }
Success #stdin #stdout 0s 5320KB
stdin
6
2 1
3 1
6 2
14142 137205
1000000 100
1000000 1000000
stdout
1
2
4
14142
500
1000000