Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cmath>
- #include <cstring>
- #include <ctime>
- #include <iostream>
- #include <algorithm>
- #include <set>
- #include <vector>
- #include <sstream>
- #include <typeinfo>
- #include <fstream>
- #include <map>
- #include <utility>
- using namespace std;
- typedef long long i64;
- typedef pair<int, int> pii;
- const i64 M = 1000000007;
- class GoodSubset {
- public:
- map<pii, i64> mp;
- vector<int> ip;
- int dp(int x, int i) {
- if(i == -1){
- if(x == 1) return 1;
- else return 0;
- }
- if(mp.find(make_pair(x, i)) != mp.end()) {
- return mp[make_pair(x, i)];
- }
- if(x % ip[i] != 0) {
- return mp[make_pair(x, i)] = dp(x, i-1);
- }
- i64 ans = 0;
- ans += dp(x, i-1);
- ans %= M;
- ans += dp(x/ip[i], i-1);
- ans %= M;
- return mp[make_pair(x, i)] = ans;
- }
- int numberOfSubsets(int goodValue, vector<int> d) {
- int N = d.size();
- for(int i=0; i<N; i++) {
- ip.push_back(d[i]);
- }
- int ans = dp(goodValue, N-1);
- if(goodValue == 1) ans--;
- return ans;
- }
- };
- int main(){
- i64 n,m;
- cin >> n >> m;
- vector<int> v(n);
- for(int i = 0; i < n; i++){
- cin >> v[i];
- }
- GoodSubset problem;
- cout << problem.numberOfSubsets(m,v) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement