fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6.  
  7. vector<int> decimalToBinary(int n){
  8. long long ans = 0;
  9. int remainder, i = 1;
  10. vector<int> v;
  11. // Until the value of n becomes 0.
  12. while(n!=0){
  13. remainder = n % 2;
  14. //ans += remainder*i;
  15. v.insert(v.begin(),remainder);
  16. i = i * 10;
  17. n = n / 2;
  18. }
  19.  
  20. return v;
  21. }
  22.  
  23. int main() {
  24. int n1 = 156;
  25. int n2 = 253;
  26. int n3 = log2(n2-n1);
  27. cout<<n3;
  28. vector<int> bin = decimalToBinary(n2);
  29.  
  30. int i =0;
  31. for ( auto x = bin.end(); x != bin.begin(); x--){
  32. if (i<n3)
  33. {
  34. cout << "1" ;
  35. }
  36. else
  37. {
  38. cout<< *x;
  39. }
  40. i++;
  41. }
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0.01s 5452KB
stdin
Standard input is empty
stdout
611111111