priyam2k

CNTSET

Jan 7th, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2.  
  3. typedef long long ll;
  4. using namespace std;
  5.  
  6. #define pb push_back
  7. #define mp make_pair
  8. #define ff first
  9. #define ss second
  10.  
  11. ll mod=1e9+7;
  12. #define int long long
  13. void io(){
  14. ios_base::sync_with_stdio(false);
  15. cin.tie(NULL);
  16. cout.tie(NULL);
  17. #ifndef ONLINE_JUDGE
  18. freopen("in8.txt","r",stdin);
  19. freopen("out8.txt","w",stdout);
  20. #endif
  21. }
  22. const int N = 1e6 + 5;
  23. long long a[20005];
  24. int n,k;
  25.  
  26. map<pair<int,int>, long long> dp;
  27.  
  28. long long solve(int id, int cur_gcd){
  29.  
  30. if(id == n){
  31. if(cur_gcd == k) return 1;
  32. else return 0;
  33. }
  34. if(dp.count(make_pair(id,cur_gcd)))
  35. return dp[make_pair(id,cur_gcd)];
  36.  
  37. int x=a[id];
  38.  
  39. long long ans=0;
  40. ans = solve(id+1,__gcd(x*cur_gcd,k));
  41.  
  42. ans += solve(id+1,cur_gcd);
  43.  
  44. if(ans >= mod) ans -= mod;
  45.  
  46. return dp[make_pair(id,cur_gcd)] = ans;
  47.  
  48. }
  49.  
  50. int32_t main()
  51. {
  52. io();
  53.  
  54. cin>>n>>k;
  55. for(int i=0;i<n;i++) cin>>a[i];
  56. int x=solve(0,1);
  57. cout<<x<<"\n";
  58.  
  59. }
Add Comment
Please, Sign In to add comment