Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- typedef long long ll;
- using namespace std;
- #define pb push_back
- #define mp make_pair
- #define ff first
- #define ss second
- ll mod=1e9+7;
- #define int long long
- void io(){
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- #ifndef ONLINE_JUDGE
- freopen("in8.txt","r",stdin);
- freopen("out8.txt","w",stdout);
- #endif
- }
- const int N = 1e6 + 5;
- long long a[20005];
- int n,k;
- map<pair<int,int>, long long> dp;
- long long solve(int id, int cur_gcd){
- if(id == n){
- if(cur_gcd == k) return 1;
- else return 0;
- }
- if(dp.count(make_pair(id,cur_gcd)))
- return dp[make_pair(id,cur_gcd)];
- int x=a[id];
- long long ans=0;
- ans = solve(id+1,__gcd(x*cur_gcd,k));
- ans += solve(id+1,cur_gcd);
- if(ans >= mod) ans -= mod;
- return dp[make_pair(id,cur_gcd)] = ans;
- }
- int32_t main()
- {
- io();
- cin>>n>>k;
- for(int i=0;i<n;i++) cin>>a[i];
- int x=solve(0,1);
- cout<<x<<"\n";
- }
Add Comment
Please, Sign In to add comment