General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
69949613 Practice:
carryup
582D - 13 GNU C++11 Accepted 592 ms 680 KB 2020-02-01 11:34:34 2020-02-01 11:34:34
→ Source
#include<bits/stdc++.h>
using namespace std;
const int P=1e9+7;
const int N=1e4+5;
char t[1005];
int p,m,n,len,a[N];
long long f[N][2][2],g[N][2][2];
int main(){
	scanf("%d%d%s",&p,&m,t),len=strlen(t);
	for(int i=0;i<len;i++)	t[i]^=48;
	reverse(t,t+len);
	while(len){
		long long k=0;
		for(int i=len-1;~i;i--){
			k=k*10+t[i],t[i]=k/p,k%=p;
			if(!t[i]&&i==len-1)	--len;
		}
		a[++n]=k;
	}	g[0][0][1]=1;
	for(int i=n;i;i--){
		memset(f,0,sizeof(f));
		long long c1=1LL*(p+1)*p/2%P;
		long long c3=1LL*(p-1)*p/2%P;
		long long c2=1LL*(a[i]+1)*a[i]/2%P;
		long long c5=1LL*(a[i]-1)*a[i]/2%P;
		long long c4=1LL*a[i]*((p<<1)-a[i]-1)/2%P;
		long long c6=1LL*a[i]*((p<<1)-a[i]+1)/2%P;
		for(int j=0;j<=n-i+1;j++){
			long long f0=g[j][0][0];
			long long f1=g[j][0][1];
			long long f2=g[j][1][0];
			long long f3=g[j][1][1];
			f[j][0][0]=(c1*f0+c2*f1+c3*f2%P+c4*f3%P)%P;
			f[j][0][1]=((a[i]+1)*f1+(p-a[i]-1)*f3)%P;
			f[j+1][1][0]=(c3*f0+c5*f1+c1*f2%P+c6*f3%P)%P;
			f[j+1][1][1]=(a[i]*f1+(p-a[i])*f3)%P;
		}
		swap(f,g);
	}
	long long ans=0;
	for(int i=m;i<=n;i++)	ans=(ans+g[i][0][0]+g[i][0][1])%P;
	printf("%lld\n",ans);
	return 0;
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details