QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#140993#6741. Digitcciafrino#AC ✓2347ms9492kbC++203.5kb2023-08-17 04:06:312023-08-17 04:06:31

Judging History

你现在查看的是最新测评结果

  • [2023-08-17 04:06:31]
  • 评测
  • 测评结果:AC
  • 用时:2347ms
  • 内存:9492kb
  • [2023-08-17 04:06:31]
  • 提交

answer

#include<bits/extc++.h>

namespace std {
struct splitmix64_hash {
	static uint64_t splitmix64(uint64_t x) {
		x += 0x9e3779b97f4a7c15;
		x = (x^(x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x^(x >> 27)) * 0x94d049bb133111eb;
		return x^(x >> 31);
	}
	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

template <typename K, typename V, typename Hash = splitmix64_hash>
using hash_map = __gnu_pbds::gp_hash_table<K, V, Hash>;
int minv(int a, int m) {
	a %= m; assert(a);
	return a == 1 ? 1 : int(m - int64_t(minv(m, a)) * m / a);
}
template<unsigned M_> struct modnum {
	static constexpr unsigned M = M_;
	using ll = int64_t; using ull = uint64_t; unsigned x;
	modnum& norm(unsigned a) { x = a < M ? a : a - M; return *this; }
	constexpr modnum(ll a = 0U) : x(unsigned((a %= ll(M)) < 0 ? a + ll(M) : a)) {}
	explicit operator int() const { return x; }
	modnum& operator+=(const modnum& a) { return norm(x + a.x); }
	modnum& operator-=(const modnum& a) { return norm(x - a.x + M); }
	modnum& operator*=(const modnum& a) { x = unsigned(ull(x) * a.x % M); return *this; }
	modnum& operator/=(const modnum& a) { return (*this *= a.inv()); }
	modnum operator+(const modnum& a) const { return (modnum(*this) += a); }
	modnum operator-(const modnum& a) const { return (modnum(*this) -= a); }
	modnum operator*(const modnum& a) const { return (modnum(*this) *= a); }
	modnum operator/(const modnum& a) const { return (modnum(*this) /= a); }
	template<typename T> friend modnum operator+(T a, const modnum& b) { return (modnum(a) += b); }
	template<typename T> friend modnum operator-(T a, const modnum& b) { return (modnum(a) -= b); }
	template<typename T> friend modnum operator*(T a, const modnum& b) { return (modnum(a) *= b); }
	template<typename T> friend modnum operator/(T a, const modnum& b) { return (modnum(a) /= b); }
	modnum operator+() const { return *this; }
	modnum operator-() const { return modnum() - *this; }
	modnum pow(ll e) const {
		if (e < 0) return inv().pow(-e);
		modnum b = x, xe = 1U;
		for (; e; e >>= 1) { if (e & 1) xe *= b; b *= b; }
		return xe;
	}
	modnum inv() const { return minv(x, M); }
	friend modnum inv(const modnum& a) { return a.inv(); }
	explicit operator bool() const { return x; }
	friend bool operator==(const modnum& a, const modnum& b) { return a.x == b.x; }
	friend bool operator!=(const modnum& a, const modnum& b) { return a.x != b.x; }
	friend ostream &operator<<(ostream& os, const modnum& a) { return os << a.x; }
	friend istream &operator>>(istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }
}; }

int main() {
	using namespace std;
	cin.tie(nullptr)->sync_with_stdio(false);
	int T; cin >> T;

	using num = modnum<998244353U>;
	using i64 = int64_t;

	while (T--) {
		i64 a, N; cin >> a >> N;

		hash_map<i64, num> dp;
		
		auto rec = [&](auto&& self, i64 X) -> num {
			if (X > N) return 0;
			if (dp.find(X) != dp.end()) return dp[X];
	
			i64 x = X;
			vector<int> digits; digits.reserve(18);
			while (x > 0) {
				digits.push_back(x % 10);
				x /= 10;
			}

			const int L = int(digits.size());
			num z = count(digits.begin(), digits.end(), 0);
			num v = 0;
			for (int i = 0; i < L; ++i) {
				if (digits[i] && digits[i] * X < N) {
					i64 nv = (digits[i] + 1) * X;
					v += self(self, nv);
				}
			}

			return dp[X] = num(L + v) / (L - z);
		};
		
		cout << rec(rec, a) << '\n';
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3468kb

input:

3
1 10
1 100
1 1000

output:

3
4
942786340

result:

ok 3 number(s): "3 4 942786340"

Test #2:

score: 0
Accepted
time: 1430ms
memory: 9328kb

input:

200
6093 473302679260560320
8548 407261659389622784
643 187875386337017408
8115 804844129595563776
3331 457909423622471360
8554 769878068775393152
2189 248771553604839360
7395 486014798136226944
8022 834223266052054400
9218 291007794161740672
8431 738787973811775616
1829 183591119896739584
816 23406...

output:

401752224
25564055
349247348
24571488
454552241
293307892
841921314
316896313
340265070
679232017
880794571
220757927
783764236
593413719
368463075
771186516
780654585
3628414
827863355
617858224
868927625
446978548
351494058
130284374
125073939
38120850
748432314
277667083
183850680
235708406
51111...

result:

ok 200 numbers

Test #3:

score: 0
Accepted
time: 196ms
memory: 6420kb

input:

200
3043059018339257 22277869996577613
9995869516 503712331451
389592 72563932968
3520234478258 476959582208156
77586585 711120211545804458
77846354 2243822883730937
9937954107 8390895135555
39032 603567
7739 4682236745217490
12277973519 7136059697857236
7264388 607094625
66205992799 4030219735546
3...

output:

108920162
651706276
549514920
440563412
796578996
851857830
191543780
540715694
549223125
380090491
553492005
247956062
582309209
67430878
174114881
1
669072219
981051601
561639793
304668111
397423058
607062211
8458982
479445466
287831358
913943402
533482140
801644611
519995972
239199505
587671914
2...

result:

ok 200 numbers

Test #4:

score: 0
Accepted
time: 2131ms
memory: 9464kb

input:

200
58 999999999999997440
75 999999999999999872
52 999999999999997696
85 999999999999999360
12 999999999999999488
77 999999999999999232
80 999999999999999232
36 999999999999997184
51 999999999999998720
79 999999999999997440
76 999999999999998592
90 999999999999997696
32 999999999999998336
67 9999999...

output:

603520497
574767370
222266238
241598642
627473669
958322466
776467011
836867165
317725053
772230956
80008248
170
205889745
956913345
252066713
183389093
251365357
387390363
836867165
660512518
265265911
574767370
317725053
620530996
15655429
247241569
103698881
940321220
960908253
960908253
66051251...

result:

ok 200 numbers

Test #5:

score: 0
Accepted
time: 683ms
memory: 9432kb

input:

200
509411 999999999999999232
33801448 999999999999998720
65 999999999999998208
6 999999999999997184
404287 999999999999999360
800418816395 999999999999999232
44589090134507 999999999999997312
2008080 999999999999999360
13 999999999999998976
87 999999999999999872
206327851576605 999999999999999744
3...

output:

883813861
221710219
620530996
252066714
168038945
932330901
77414612
443356611
1883978
608670663
568648025
891202485
151357997
793825022
180372901
749235099
391331669
890726608
103698881
258627374
738512765
18273750
771644777
916674174
110687232
890972839
85823452
799141196
739829892
675630993
44879...

result:

ok 200 numbers

Test #6:

score: 0
Accepted
time: 2347ms
memory: 9492kb

input:

200
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 10000000...

output:

252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
...

result:

ok 200 numbers