Submission #70364105


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll T, c, d;

ll f(ll x)
{
	ll res = sqrt(x);
	while (res * res > x) res--;
	while ((res + 1) * (res + 1) <= x) res++;
	return res;
}

int main()
{
	cin >> T;
	
	while (T--)
	{
		cin >> c >> d;
		
		ll x = 10, mn = 1, mx = 9, ans = 0;
		while (mn <= c + d)
		{
			ll l = max(c + 1, mn);
			ll r = min(c + d, mx);
			if (l <= r)
			{
				ll tl = c * x + l;
				ll tr = c * x + r;
				ans += (f(tr) - f(tl - 1));
			}
			
			mn *= 10;
			mx = (mx + 1) * 10 - 1;
			x *= 10;
		}
		cout << ans << endl;
	}
	
	return 0;
}

Submission Info

Submission Time
Task D - 183184
User peterJr
Language C++ 20 (gcc 12.2)
Score 400
Code Size 630 Byte
Status AC
Exec Time 446 ms
Memory 3596 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 3524 KiB
01-01.txt AC 414 ms 3548 KiB
01-02.txt AC 414 ms 3416 KiB
01-03.txt AC 446 ms 3596 KiB
01-04.txt AC 442 ms 3524 KiB
01-05.txt AC 414 ms 3520 KiB
01-06.txt AC 396 ms 3544 KiB
01-07.txt AC 424 ms 3472 KiB
01-08.txt AC 404 ms 3596 KiB
01-09.txt AC 439 ms 3516 KiB