QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#647287 | #7954. Special Numbers | ucup-team5234# | WA | 1ms | 3828kb | C++23 | 5.7kb | 2024-10-17 13:13:18 | 2024-10-17 13:13:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
#define rep(i, n) for(int i=0;i<n;i++)
#define foa(e, v) for(auto& e : v)
using ll = long long;
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 60);
#define dout(a) cout<<fixed<<setprecision(10)<<a<<endl;
template<int MOD> struct Modint {
long long val;
constexpr Modint(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; }
constexpr int mod() const { return MOD; }
constexpr long long value() const { return val; }
constexpr Modint operator - () const noexcept { return val ? MOD - val : 0; }
constexpr Modint operator + (const Modint& r) const noexcept { return Modint(*this) += r; }
constexpr Modint operator - (const Modint& r) const noexcept { return Modint(*this) -= r; }
constexpr Modint operator * (const Modint& r) const noexcept { return Modint(*this) *= r; }
constexpr Modint operator / (const Modint& r) const noexcept { return Modint(*this) /= r; }
constexpr Modint& operator += (const Modint& r) noexcept {
val += r.val;
if (val >= MOD) val -= MOD;
return *this;
}
constexpr Modint& operator -= (const Modint& r) noexcept {
val -= r.val;
if (val < 0) val += MOD;
return *this;
}
constexpr Modint& operator *= (const Modint& r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Modint& operator /= (const Modint& r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b, swap(a, b);
u -= t * v, swap(u, v);
}
val = val * u % MOD;
if (val < 0) val += MOD;
return *this;
}
constexpr bool operator == (const Modint& r) const noexcept { return this->val == r.val; }
constexpr bool operator != (const Modint& r) const noexcept { return this->val != r.val; }
friend constexpr istream& operator >> (istream& is, Modint<MOD>& x) noexcept {
is >> x.val;
x.val %= MOD;
if (x.val < 0) x.val += MOD;
return is;
}
friend constexpr ostream& operator << (ostream& os, const Modint<MOD>& x) noexcept {
return os << x.val;
}
constexpr Modint<MOD> pow(long long n) noexcept {
if (n == 0) return 1;
if (n < 0) return this->pow(-n).inv();
Modint<MOD> ret = pow(n >> 1);
ret *= ret;
if (n & 1) ret *= *this;
return ret;
}
constexpr Modint<MOD> inv() const noexcept {
long long a = this->val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b, swap(a, b);
u -= t * v, swap(u, v);
}
return Modint<MOD>(u);
}
};
const int MOD = MOD7;
using mint = Modint<MOD>;
mint solve(string s, ll k) {
vector<vector<ll>> cc(10, vector(10, 0LL));
for(ll i = 0; i < 10; i ++) {
if(i == 0) {
rep(j, 10) cc[i][j] = 100;
} else {
ll num = i;
for(ll j = 2; j < 10; j ++) {
while(num % j == 0) {
num /= j;
cc[i][j] ++;
}
}
}
}
vector<ll> c(10, 0);
for(ll i = 2; i < 10; i ++) {
while(k % i == 0) {
k /= i;
c[i] ++;
}
}
if(k > 1) {
return mint(0);
}
vector dp(c[2] + 1, vector(c[3] + 1, vector(c[5] + 1, vector(c[7] + 1, mint(0)))));
mint ans = 0;
ll n = s.size();
vector<ll> now(10, 0);
rep(i, n) {
vector nx(c[2] + 1, vector(c[3] + 1, vector(c[5] + 1, vector(c[7] + 1, mint(0)))));
rep(c2, c[2] + 1) {
rep(c3, c[3] + 1) {
rep(c5, c[5] + 1) {
rep(c7, c[7] + 1) {
for(int j = 0; j < 10; j ++) {
nx[min(c[2], c2 + cc[j][2])][min(c[3], c3 + cc[j][3])][min(c[5], c5 + cc[j][5])][min(c[7], c7 + cc[j][7])]
+= dp[c2][c3][c5][c7];
}
}
}
}
}
int num = s[i] - '0';
vector<ll> nnx(10, 0);
for(int j = 0; j < num; j ++) {
if(i == 0 and j == 0) continue;
nx[min(c[2], now[2] + cc[j][2])][min(c[3], now[3] + cc[j][3])][min(c[5], now[5] + cc[j][5])][min(c[7], now[7] + cc[j][7])] += mint(1);
}
if(i) {
for(ll j = 1; j < 10; j ++) {
nx[min(c[2], cc[j][2])][min(c[3], cc[j][3])][min(c[5], cc[j][5])][min(c[7], cc[j][7])] += mint(1);
}
}
{
for(ll x = 2; x < 10; x ++) {
nnx[x] = now[x] + cc[num][x];
}
}
swap(nnx, now);
swap(nx, dp);
}
bool ng = 0;
for(ll i = 2; i < 10; i ++) {
if(now[i] < c[i]) ng = 1;
}
if(!ng) ans += mint(1);
ans += dp[c[2]][c[3]][c[5]][c[7]];
return ans;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll k;
cin >> k;
string l, r;
cin >> l >> r;
if(l == "1") {
cout << solve(r, k) << endl;
} else {
reverse(all(l));
int n = l.size();
rep(i, n) {
if(l[i] > '0') {
int num = l[i] - '0';
l[i] = char('0' + (num - 1));
} else {
l[i] = '9';
}
}
if(l.back() == '0') l.pop_back();
reverse(all(l));
cout << solve(r, k) - solve(l, k) << endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
5 1 20
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
5 50 100
output:
19
result:
ok single line: '19'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
15 11 19
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
1 100 100000
output:
99901
result:
ok single line: '99901'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
1 1 1
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
10 800 43021
output:
23570
result:
ok single line: '23570'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
1125899906842624 1 100000000000000000000
output:
555058180
result:
ok single line: '555058180'
Test #8:
score: -100
Wrong Answer
time: 1ms
memory: 3812kb
input:
187500000 5941554024261918062 17356601866920567143
output:
399086660
result:
wrong answer 1st lines differ - expected: '679191360', found: '399086660'