#include <bits/stdc++.h> using namespace std; char a[11], n; int f[11][100], p, q, k;…
- User
#include <bits/stdc++.h> using namespace std; char a[11], n; int f[11][100], p, q, k; int F(int i, bool gh, int s) { if (i<0) if (s%k==0) return 1; else return 0; if (!gh && f[i][s]>=0) return f[i][s]; char maxc=gh ? a[i] : 9; int res=0; for (char c=0; c<=maxc; c++) { bool ghm=gh && (c==maxc); res+=F(i-1,ghm,s+c); } if (!gh) f[i][s]=res; return res; }
int G(int x) { n=0; while (x!=0) { a[n]=x%10; x/=10; n++; } return F(n-1,true,0); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); freopen("bai2.inp","r",stdin); freopen("bai2.out","w",stdout); memset(f,-1,sizeof(f)); cin >> p >> q >> k; cout << G(q)-G(p-1); return 0; }
- Assistant