Reprinted please indicate the source, thank youHttp://blog.csdn.net/acm_cxlove/article/details/7854526
By --- cxlove
Question: Given the N numbers of 1-N, how many subsets are there? The LCM in the set is greater than or equal to M.
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4028
We can find that the range of M is very large, and the subset of 1-N is also a lot of 2 ^ N-1.
I think it would be DP, but the data range is too large to start.
In fact, we can find that although there are many subsets, but the LCM value is not so much, so we can use map to save the number of I-1 when all the LCM values
In this way, you can transfer
Map <LL, ll> DP [I]. Indicates the number of I, which can be it-> second to form it-> first.
# Include <iostream> # include <cstdio> # include <map> # include <cstring> # include <cmath> # include <vector> # include <queue> # include <algorithm> # include <set> # define INF 110000 # define M 10005 # define n 10005 # define min (, b) (a) <(B )? (A) :( B) # define max (A, B) (a)> (B )? (A) :( B) # define Pb (a) push_back (a) # define MEM (a, B) memset (a, B, sizeof ()) # define EPS 1e-9 # define zero (a) FABS (a) <EPS # define ll long # define mod 1000000007 using namespace STD; Map <LL, ll> DP [45]; map <LL, ll >:: iterator it; ll gcd (ll a, LL B) {return B = 0? A: gcd (B, A % B);} ll lcm (ll a, LL B) {return a/gcd (a, B) * B;} void dp () {DP [1] [1] = 1; for (INT I = 2; I <= 40; I ++) {DP [I] = DP [I-1]; // if you do not specify the number of I, copy DP [I] [I] ++ first. // you can only specify the number of I, cannot fall for (IT = DP [I-1]. begin (); it! = DP [I-1]. end (); It ++) DP [I] [lcm (I, IT-> first)] + = it-> second; // then consider adding the I number} ll n, m; int main () {dp (); int T, CAS = 0 on the basis of the previous number of I-1; scanf ("% d", & T); While (t --) {scanf ("% i64d % i64d", & N, & M); LL ans = 0; // traverse for (IT = DP [N]. begin (); it! = DP [N]. end (); It ++) if (IT-> first> = m) ans + = it-> second; printf ("case # % d: % i64d \ n ", + cas, ANS);} return 0 ;}