Advertisement
peter8901

22 4

Feb 16th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream fin("BAC.txt");
  7. int a,b,n;
  8. int h(int n) {
  9. int p=1;
  10. while(p<n){
  11. p*=2;
  12. }
  13. if(p==n) return 1;
  14. else return 0;
  15. }
  16.  
  17. int main() {
  18. fin>>n;
  19. for (int i=1; i<=n; i++) {
  20. fin>>a>>b;
  21. for(int i=b;i>=a;i--){
  22. if(h(i)){
  23. cout<<i<<" ";
  24. break;
  25. }
  26. if(i==a && !h(i)) cout<<0<<" ";
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement