Skip to content

Commit

Permalink
25958
Browse files Browse the repository at this point in the history
  • Loading branch information
IsuminI authored Jul 24, 2024
1 parent b4bafcc commit 9cb5707
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions 이수민/25958.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
int check[5001];
long long int dp[5001][5001];
int main()
{
for(int i=1; i<=5000; i++) {
int sum = 0;
int k = i;
while(k) {
sum += k%10;
k /= 10;
}
if(i % sum == 0) check[i] = 1;
}
int m,k;
scanf("%d %d",&m,&k);
for(int i=1; i<=m; i++) dp[0][i] = 1;
for(int i=1; i<=m; i++) {
for(int j=1; j<=m; j++) {
if(!check[j] || j > i) {dp[i][j] += dp[i][j-1]; continue;}
dp[i][j] = dp[i-j][j] % k;
dp[i][j] += dp[i][j-1];
dp[i][j] = ((dp[i][j] % k) + (dp[i][j-1] % k)) % k;
}
}
printf("%lld",dp[m][m] % k);
return 0;
}

0 comments on commit 9cb5707

Please sign in to comment.