Submission #70251401


Source Code Expand

#include<bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
using namespace std;

inline void solve() {
	LL aa, bb, ans = 0; cin >> aa >> bb; __int128 c = (__int128)aa + 1, b = bb, a = aa; b = b - 1;
	int t = 0; LL vl = a;
	while (vl) {
		t++;
		vl /= 10;
	}
	vector<__int128> p(24); p[0] = 1;
	for (int i = 1; i <= 23; i++) p[i] = p[i - 1] * (__int128)10;
	while (b >= 0) {
		__int128 z = (__int128)a * p[t] + c, y = (__int128)a * p[t] + min(p[t] - 1, c + (__int128)b);
		__int128 l = sqrt(z + 0.5), r = sqrt(y + 0.5); 
		while (l * l < z) l++;
		while ((l - 1) * (l - 1) >= z) l--;
		while ((r + 1) * (r + 1) <= y) r++;
		while (r * r > y) r--;
		ans += max((__int128)0, r - l + 1);
//		cout << t << " " << (LL)z << " " << (LL)y << " " << (LL)l << " " << (LL)r << " " << (LL)(l * l) << " " << (LL)(r * r) << "\n";
		b -= p[t] - c;
		t++; c = p[t - 1];
	}
	cout << ans << "\n";
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	int t = 1;
	cin >> t;
	while (t--) solve();
	return 0;
}

Submission Info

Submission Time
Task D - 183184
User C202627yehan
Language C++ 20 (gcc 12.2)
Score 400
Code Size 1120 Byte
Status AC
Exec Time 132 ms
Memory 3632 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 1
AC × 10
Set Name Test Cases
Sample 00-sample-01.txt
All 00-sample-01.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 1 ms 3448 KiB
01-01.txt AC 131 ms 3632 KiB
01-02.txt AC 132 ms 3564 KiB
01-03.txt AC 73 ms 3356 KiB
01-04.txt AC 77 ms 3356 KiB
01-05.txt AC 132 ms 3608 KiB
01-06.txt AC 81 ms 3444 KiB
01-07.txt AC 86 ms 3360 KiB
01-08.txt AC 87 ms 3528 KiB
01-09.txt AC 102 ms 3428 KiB