esraa_syam

Untitled

Jul 17th, 2024
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ull unsigned long long
  4. #define endl '\n'
  5. #define EPS 1e-9
  6. using namespace std;
  7. void Haidy();
  8.  
  9. const ll MOD = (int)1e9 + 7;
  10. const auto PI = std::acos(-1);
  11.  
  12. int knightX[] = {-2, -2, 2, 2, 1, 1 , -1, -1};
  13. int knighty[] = {-1, 1, -1, 1, -2, 2, -2, 2};
  14.  
  15. int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};
  16. int dy[] = {0, -1, 0, 1, -1, 1, -1, 1};
  17. char di[] = {'D', 'L', 'U', 'R'};
  18.  
  19.  
  20. int l , r;
  21. vector<int> spf[55], primes;
  22. bool isPrime(int n){
  23. if(n == 1) return 0;
  24. for(int i = 2; i < n; i++){
  25. if(n%i == 0)
  26. return 0;
  27. }
  28. return 1;
  29. }
  30. void pre(){
  31. for(int i = 2; i<=50; i++){
  32. if(isPrime(i))
  33. primes.push_back(i);
  34. for(auto p: primes){
  35. if(i %p == 0){
  36. spf[i].push_back(p);
  37. }
  38. }
  39. }
  40. }
  41.  
  42. int target;
  43. vector < vector < ll > > dp;
  44.  
  45. ll rec(int cur_sum , int msk){
  46. if(cur_sum >= target){
  47. return cur_sum == target;
  48. }
  49.  
  50. ll ret = 0;
  51. for(int i = 1; i <= 50; i++){
  52. bool ok = 1;
  53. for(auto& p : spf[i]){
  54. for(int k = 0 ; k < primes.size() ; k++){
  55. // only one pit 1
  56. if(p == primes[k]) if(msk & (1 << k)) ok = 0;
  57. }
  58.  
  59. }
  60. if(ok){
  61. for(auto& p : spf[i]){
  62. for(int k = 0 ; k < primes.size() ; k++){
  63. // only one pit 1
  64. if(p == primes[k]) msk |= (1 << k);
  65. }
  66.  
  67. }
  68. ret += rec(cur_sum+i, msk);
  69.  
  70. for(auto& p : spf[i]){
  71. for(int k = 0 ; k < primes.size() ; k++){
  72. // only one pit 1
  73. if(p == primes[k]) msk &= !(1 << k);
  74.  
  75. }
  76.  
  77. }
  78.  
  79. }
  80. }
  81. return ret;
  82. }
  83.  
  84.  
  85. void solveTest() {
  86. cin >> l >> r;
  87. ll ans = 0;
  88. for(int i =l ; i <= r; i++){
  89. target =i;
  90. ans += rec(0, set<int>());
  91. }
  92. cout << ans << endl;
  93. }
  94.  
  95. int main() {
  96. Haidy();
  97. pre();
  98. int testCases = 1;
  99. cin >> testCases;
  100. cout << fixed << setprecision(9);
  101. while(testCases--) {
  102. solveTest();
  103. }
  104. return 0;
  105. }
  106.  
  107. void Haidy() {
  108. cin.tie(nullptr), cout.tie(nullptr), cin.sync_with_stdio(false), cout.sync_with_stdio(false);
  109. #ifdef Clion
  110. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  111. #endif
  112. }
Advertisement
Add Comment
Please, Sign In to add comment