QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#580194 | #9139. Prefix Divisible by Suffix | orz_z | AC ✓ | 6908ms | 3832kb | C++14 | 4.2kb | 2024-09-21 20:26:54 | 2024-09-21 20:26:54 |
Judging History
answer
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
//#pragma GCC optimize("Ofast,fast-math")
//#pragma GCC target("avx,avx2")
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int __int128
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;
#define F(i, a, b) for(int i = a; i <= (b); ++i)
#define F2(i, a, b) for(int i = a; i < (b); ++i)
#define dF(i, a, b) for(int i = a; i >= (b); --i)
template<typename T> void debug(string s, T x) {
cerr << "[" << s << "] = [" << x << "]\n";
}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {
for (int i = 0, b = 0; i < (int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++;
else if (s[i] == ')' || s[i] == '}') b--;
else if (s[i] == ',' && b == 0) {
cerr << "[" << s.substr(0, i) << "] = [" << x << "] | ";
debug(s.substr(s.find_first_not_of(' ', i + 1)), args...);
break;
}
}
#ifdef ONLINE_JUDGE
#define Debug(...)
#else
#define Debug(...) debug(#__VA_ARGS__, __VA_ARGS__)
#endif
#define pb push_back
#define fi first
#define se second
#define Mry fprintf(stderr, "%.3lf MB\n", (&Med - &Mbe) / 1048576.0)
#define Try cerr << 1e3 * clock() / CLOCKS_PER_SEC << " ms\n";
typedef long long ll;
// namespace Fread {const int SIZE = 1 << 17; char buf[SIZE], *S, *T; inline char getchar() {if (S == T) {T = (S = buf) + fread(buf, 1, SIZE, stdin); if (S == T) return '\n';} return *S++;}}
// namespace Fwrite {const int SIZE = 1 << 17; char buf[SIZE], *S = buf, *T = buf + SIZE; inline void flush() {fwrite(buf, 1, S - buf, stdout), S = buf;} inline void putchar(char c) {*S++ = c;if (S == T) flush();} struct NTR {~NTR() {flush();}} ztr;}
// #ifdef ONLINE_JUDGE
// #define getchar Fread::getchar
// #define putchar Fwrite::putchar
// #endif
inline int ri() {
int x = 0;
bool t = 0;
char c = getchar();
while (c < '0' || c > '9') t |= c == '-', c = getchar();
while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return t ? -x : x;
}
inline void wi(int x) {
if (x < 0) {
putchar('-'), x = -x;
}
if (x > 9) wi(x / 10);
putchar(x % 10 + 48);
}
inline void wi(int x, char s) {
wi(x), putchar(s);
}
bool Mbe;
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3f;
const int _ = 2e5 + 5;
int n, c;
int fac[15];
//ll dfs(int u, int dep) {
// if(dep > lim) return 0;
// ll res = 0;
// if(u <= C[dep]) {
// res += get(u + c, 1, B[dep]);
// } else {
// res += get(u + c, 0, B[dep]);
// }
//// Debug(u, dep, res);
// F(i, 0, 9) {
// res += dfs(u * 10 + i, dep + 1);
//// Debug(i, tk[i]);
//// res -= tk[i];
// }
// return res;
//}
int exgcd(int a, int b, int &x, int &y) {
if(!b) {
x = 1, y = 0;
return a;
}
int g = exgcd(b, a % b, y, x);
y -= a / b * x;
return g;
}
pii merge(int m1, int a1, int m2, int a2) {
// n=k1m1+a1=k2m2+a2
// n = -a1 mod m1
// n= -a2 mod m2
// k1m1 - k2m2 = a2 - a1
// xm1+ym2=gcd(m1,m2)
// xm1+ym2=a2-a1
// n=k1m1+a1=xm1+a1
int x, y;
int g = exgcd(m1, m2, x, y);
if((a2 - a1) % g != 0) return {-1, 0};
int v = (a2 - a1) / g;
x *= v;
int m3 = m1 / g * m2;
x = x * m1 + a1;
int n = (x % m3 + m3) % m3;
return make_pair(m3, n);
}
int dfs(int u, int dep, int i, int m, int a) {
// 以a结尾,是m的倍数
// km+a<=n 且
// 已到u,dep
if(a > n) return 0;
ll res = (n - a) / m + 1;
// Debug(u, dep, i, m, a);
if(a < fac[dep]) {
res -= (fac[dep] - a - 1) / m + 1;
}
F(j, 1, i - 1) {
int v2 = u % fac[j];
pii p = merge(m, a, (v2 + c) * fac[j], v2);
if(p.fi == -1) continue;
res -= dfs(u, dep, j, p.fi, p.se); // 减掉下一位满足的情况
}
return res;
}
bool Med;
signed main() {
// Mry;
n = ri(), c = ri();
fac[0] = 1;
F(i, 1, 14) fac[i] = 10ll * fac[i - 1];
ll ans = 0;
F(fk, 1, 7) {
int l = (fk == 1 ? 0 : fac[fk - 1]), r = fac[fk] - 1;
F(i, l, r) ans += dfs(i, fk, fk, (i + c) * fac[fk], i);
}
wi(ans, '\n');
// Try;
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 44ms
memory: 3788kb
input:
20 1
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 44ms
memory: 3504kb
input:
111 4
output:
9
result:
ok 1 number(s): "9"
Test #3:
score: 0
Accepted
time: 45ms
memory: 3588kb
input:
1111 10
output:
75
result:
ok 1 number(s): "75"
Test #4:
score: 0
Accepted
time: 461ms
memory: 3596kb
input:
1000000 7
output:
111529
result:
ok 1 number(s): "111529"
Test #5:
score: 0
Accepted
time: 44ms
memory: 3824kb
input:
1 1
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 88ms
memory: 3560kb
input:
99999 10000
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 44ms
memory: 3588kb
input:
1000 1
output:
287
result:
ok 1 number(s): "287"
Test #8:
score: 0
Accepted
time: 5539ms
memory: 3528kb
input:
10000000 1
output:
3102010
result:
ok 1 number(s): "3102010"
Test #9:
score: 0
Accepted
time: 5467ms
memory: 3524kb
input:
100000000 1
output:
31035571
result:
ok 1 number(s): "31035571"
Test #10:
score: 0
Accepted
time: 5543ms
memory: 3476kb
input:
1000000000 1
output:
310375697
result:
ok 1 number(s): "310375697"
Test #11:
score: 0
Accepted
time: 5466ms
memory: 3820kb
input:
10000000000 1
output:
3103907933
result:
ok 1 number(s): "3103907933"
Test #12:
score: 0
Accepted
time: 5483ms
memory: 3588kb
input:
100000000000 1
output:
31039265058
result:
ok 1 number(s): "31039265058"
Test #13:
score: 0
Accepted
time: 5527ms
memory: 3752kb
input:
1000000000000 1
output:
310394177863
result:
ok 1 number(s): "310394177863"
Test #14:
score: 0
Accepted
time: 5523ms
memory: 3828kb
input:
10000000000000 1
output:
3103943538348
result:
ok 1 number(s): "3103943538348"
Test #15:
score: 0
Accepted
time: 5673ms
memory: 3832kb
input:
100000000000000 1
output:
31039449626535
result:
ok 1 number(s): "31039449626535"
Test #16:
score: 0
Accepted
time: 5892ms
memory: 3584kb
input:
100000000000000 10
output:
9041696367054
result:
ok 1 number(s): "9041696367054"
Test #17:
score: 0
Accepted
time: 6092ms
memory: 3504kb
input:
100000000000000 100
output:
1744469671929
result:
ok 1 number(s): "1744469671929"
Test #18:
score: 0
Accepted
time: 6405ms
memory: 3500kb
input:
100000000000000 1000
output:
263959224215
result:
ok 1 number(s): "263959224215"
Test #19:
score: 0
Accepted
time: 6897ms
memory: 3816kb
input:
100000000000000 10000
output:
35400402243
result:
ok 1 number(s): "35400402243"
Test #20:
score: 0
Accepted
time: 6215ms
memory: 3528kb
input:
100000000000000 239
output:
870346971377
result:
ok 1 number(s): "870346971377"
Test #21:
score: 0
Accepted
time: 6124ms
memory: 3472kb
input:
99999987654321 111
output:
1606282527743
result:
ok 1 number(s): "1606282527743"
Test #22:
score: 0
Accepted
time: 6887ms
memory: 3524kb
input:
96709210826727 9568
output:
35605797003
result:
ok 1 number(s): "35605797003"
Test #23:
score: 0
Accepted
time: 6849ms
memory: 3820kb
input:
22952388910151 8412
output:
9470863043
result:
ok 1 number(s): "9470863043"
Test #24:
score: 0
Accepted
time: 6610ms
memory: 3568kb
input:
49191272026279 3065
output:
49381052989
result:
ok 1 number(s): "49381052989"
Test #25:
score: 0
Accepted
time: 6908ms
memory: 3596kb
input:
75434450109703 9205
output:
28741533023
result:
ok 1 number(s): "28741533023"
Test #26:
score: 0
Accepted
time: 6286ms
memory: 3528kb
input:
1677628193127 753
output:
5631822336
result:
ok 1 number(s): "5631822336"
Test #27:
score: 0
Accepted
time: 6827ms
memory: 3528kb
input:
1000010000 10000
output:
328824
result:
ok 1 number(s): "328824"
Extra Test:
score: 0
Extra Test Passed