思路:
然后dp即可
#include <bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define inf 0x3f3f3f3f #define ll long long #define pb push_back #define PII pair<int,int> #define X first #define Y second #define MP make_pair #define PI acos(-1.0) #define eps 1e-8 const int maxn=1e6+10; const int mod=998244353; using namespace std; int n,m,ans; ll dp[1005][1005]; ll solve(int all,int k) { if(all==0||k==1) return 1; if(k>all) return solve(all,k); return (solve(all,k-1)+solve(all-k,k))%mod; } int main() { scanf("%d%d",&n,&m); int x=1,y=1; for(int i=2;i*i<=m;i++) { int tmp=0; while(m%i==0) tmp++,m/=i; if(tmp&1) y*=i,tmp--; for(int j=0;j<tmp/2;j++) x*=i; } if(m>1) y*=m; dp[0][0]=1; for (int i=1;i<=x;i++) { for (int j=1;j<=i;j++) { if(i>=j) { dp[i][j]=(dp[i-1][j-1]+dp[i-j][j])%mod; } else { dp[i][j]=dp[i][i]; } } } ll ans=0; for(int i=1;i<=n;i++) ans+=dp[x][i],ans%=mod; printf("%lld",ans); // system("pause"); return 0; }