網易的一道筆試題
阿新 • • 發佈:2019-01-10
3
#include <iostream> #include<vector> #include<algorithm> #include<cmath> //#define mod 1,000,000,007 using namespace std; int main() { int n,k; int mod= 1000000007; while(cin>>n>>k) { //vector <vector<int> (k+1,0)> a(n+1); int **a; a=new int* [n+1]; for(int i=0;i<n+1;i++) a[i]=new int[k+1](); a[0][1]=1; for(int i=1;i<=n;i++) { int sum=0,val=0;; for(int j=1;j<=k;j++) {sum+=a[i-1][j];sum%=mod;}//cout<<a[i-1][j]<<" "; for(int j=1;j<=k;j++) { int p=2;val=0; while(p*j<=k) { val+=a[i-1][p*j]; p++;val%=mod; } a[i][j]=(sum-val)%mod; } } int out=0; for(int j=1;j<=k;j++) {out+=a[n][j];out%=mod;} cout<<out<<endl; } }