Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #include <set>
  5. #include <queue>
  6. #include <algorithm>
  7. #include <string>
  8. #include <cmath>
  9. #include <cstdio>
  10. #include <iomanip>
  11. #include <fstream>
  12. #include <cassert>
  13. #include <cstring>
  14. #include <unordered_set>
  15. #include <unordered_map>
  16. #include <numeric>
  17. #include <ctime>
  18. #include <bitset>
  19. #include <complex>
  20. #include <random>
  21.  
  22. using namespace std;
  23.  
  24. #define int long long
  25.  
  26. int n;
  27.  
  28. int cnt(int x) {
  29. int ans = 0;
  30. int move = 0;
  31. // while (x % 2 == 0 && x > 2) {
  32. // x >>= 1;
  33. // }
  34. int tx = x;
  35. while (x <= n) {
  36. int ebn = n;
  37. for (int i = 4; i >= 0; i--) {
  38. if ((x >> i) & 1LL) {
  39. break;
  40. }
  41. if ((ebn >> i) & 1LL) {
  42. if (x <= ebn - (1LL << i)) {
  43. ebn ^= (1LL << i);
  44. }
  45. }
  46. }
  47. ans += max((int)0, min(1LL << move, ebn - x + 1));
  48. x <<= 1;
  49. move++;
  50. }
  51. if (tx % 2 == 0) {
  52. x = tx + 1;
  53. ans += cnt(tx + 1);
  54. }
  55. return ans;
  56. }
  57.  
  58. signed main() {
  59. ios_base::sync_with_stdio(false);
  60. cin.tie(0);
  61. //BACK IN 92
  62.  
  63. //8 + 2 + 1
  64. int k;
  65. cin >> n >> k;
  66.  
  67. // for (int i = 1; i <= n; i++) {
  68. // cout << cnt(i) << ' ';
  69. // }
  70. // cout << endl;
  71.  
  72. cout << cnt(3) << endl;
  73.  
  74. // int r = n;
  75. // int l = 1;
  76. // while (r - l > 1) {
  77. // int m = (r + l) >> 1;
  78. // if (cnt(m) >= k) {
  79. // l = m;
  80. // } else {
  81. // r = m;
  82. // }
  83. // }
  84. // cout << l << endl;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement