intdfs(int x) { if (x < 10) return x; return dfs(f[x]); } inlineintG(int x) { int r = 1; while (x) { int t = x % 10; if (t) r = r * t; x /= 10; } return r; } intmain(void) { int q, l, r, k, i; for (i = 1; i <= 1000000; ++i) f[i] = G(i); for (i = 1; i <= 1000000; ++i) { g[i] = dfs(i); pos[g[i]].push_back(i); } for (i = 1; i <= 9; ++i) sort(pos[i].begin(), pos[i].end()); scanf("%d", &q); while (q--) { scanf("%d%d%d", &l, &r, &k); printf("%d\n", upper_bound(pos[k].begin(), pos[k].end(), r) - lower_bound(pos[k].begin(), pos[k].end(), l)); } return0; }
intmain(void) { int n, a, b, i; while (~scanf("%d%d%d", &n, &a, &b)) { int flag = 0; int kk = 0; for (int k1 = 0; a * k1 <= n; ++k1) { if ((n - (a * k1)) % b == 0) { flag = 1; kk = k1; break; } } if (!flag) puts("-1"); else { int K1 = kk, K2 = (n - (a * K1)) / b; int lastpos = 1; while (K1--) { for (i = lastpos; i <= n; ++i) { if (!vis[i]) { vis[i] = 1; arr[i] = i + a - 1; int last = i + a - 1; lastpos = last; for (int j = i + a - 1; j > i; --j) arr[j] = --last, vis[j] = 1; break; } } } while (K2--) { for (i = lastpos; i <= n; ++i) { if (!vis[i]) { vis[i] = 1; arr[i] = i + b - 1; int last = i + b - 1; lastpos = last; for (int j = i + b - 1; j > i; --j) arr[j] = --last, vis[j] = 1; break; } } } for (i = 1; i <= n; ++i) printf("%d%c", arr[i], " \n"[i == n]); } } return0; }
LL qpow(LL a, LL b) { LL r = 1; while (b) { if (b & 1) r = r * a % mod; a = a * a % mod; b >>= 1; } return r; } LL dfs(int res, int b, int tot) { if (dp[res][b]) return dp[res][b]; int c = tot - b; if (!res) return dp[res][b] = qpow(2LL, (LL)c); if (b) { LL s = 1LL * b * dfs(res - 1, b, tot); dp[res][b] = (dp[res][b] + s) % mod; } if (c) { LL s = 1LL * c * dfs(res - 1, b + 1, tot); dp[res][b] = (dp[res][b] + s) % mod; } return dp[res][b]; } intmain(void) { while (~scanf("%I64d%I64d", &n, &k)) { printf("%I64d\n", dfs(k, 0, n) % mod); } return0; }