➤ Problem Link : 414B. Mashmokh and ACM
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; #define ll long long int #define m 1000000007 int main() { int n,k; cin>>n>>k; vector<int> arr[n+1]; for(int i=1;i<=n;i++) { for(int j=1;j*j<=i;j++) { if(i%j!=0) continue; arr[i].push_back(j); if(j!=i/j) arr[i].push_back(i/j); } } ll dp[k+1][n+1]; memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) dp[1][i]=1; ll ans=0; for(int i=2;i<=k;i++) { for(int j=1;j<=n;j++) { for(int k=0;k<arr[j].size();k++) dp[i][j]=(dp[i][j]+dp[i-1][arr[j][k]])%m; } } for(int i=1;i<=n;i++) ans=(ans+dp[k][i])%m; cout<<ans; }
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!