Pagini recente » Cod sursa (job #394182) | Cod sursa (job #2566013) | Cod sursa (job #2229579) | Cod sursa (job #3142965) | Cod sursa (job #2618790)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("diviz.in");
ofstream fout("diviz.out");
const int nmax = 200, mod = 98551;
int k, a, b, n, v[nmax + 5], pos[10][nmax + 5];
char ch;
int solve(int index, int cif, int nr)
{
if (index == n + 1) return cif >= a && cif <= b && nr == 0;
int start = 0;
if (cif == 0) ++start;
int ans = solve(n + 1, cif, nr);
for (int i = start; i <= 9; ++i)
{
int next = pos[i][index];
if (next <= n) ans += solve(next + 1, cif + 1, (nr * 10 + i) % k);
}
return ans;
}
int main()
{
fin >> k >> a >> b;
while (fin >> ch) v[++n] = ch - '0';
fout << solve(1, 0, 0);
fin.close();
fout.close();
return 0;
}