You are given two integers AA and BB, calculate the number of pairs (a,b)(a,b) such that 1≤a≤A1≤a≤A, 1≤b≤B1≤b≤B, and the equation a⋅b+a+b=conc(a,b)a⋅b+a+b=conc(a,b) is true; conc(a,b)conc(a,b) is the concatenation of aa and bb (for example, conc(12,23)=1223conc(12,23)=1223, conc(100,11)=10011conc(100,11)=10011). aa and bb should not contain leading zeroes.
Input
The first line contains tt (1≤t≤1001≤t≤100) — the number of test cases.
Each test case contains two integers AA and BB (1≤A,B≤109)(1≤A,B≤109).
Output
Print one integer — the number of pairs (a,b)(a,b) such that 1≤a≤A1≤a≤A, 1≤b≤B1≤b≤B, and the equation a⋅b+a+b=conc(a,b)a⋅b+a+b=conc(a,b) is true.
Example
input
Copy
3
1 11
4 2
191 31415926
output
Copy
1 0 1337
Note
There is only one suitable pair in the first test case: a=1a=1, b=9b=9 (1+9+1⋅9=191+9+1⋅9=19).
打表发现规律
一直到a结束。当b小于9的话,根本不可能输出,这时候涉及位数问题,上面,位数有八位,所以有7个9,也就是位数-1,而当b等于9,99,999之类的时候和10,100,1000的位数是一样的,所以要讨论。
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<cmath>
#include<string.h>
using namespace std;
// ctrl+shift+C 注释
//ctrl+shift+x 取消
#define int long long
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef pair<int,int> PII;
const int N=2e5+10;
const ll M=1e18+10;
const int mod=1e9+7;
int aa[N],sum[N];
priority_queue<int,vector<int>,greater<int> >pq;
set<int>se;
map<int,int>mp;
queue<int>qu;
vector<int>v;
deque<int>de;
int a,b;
int ws(int b)
{
int k=0;
while(b)
{
b/=10;
k++;
}
return k;
}
void solve()
{
cin>>a>>b;
if(b<9)cout<<0<<endl;
else
{
int res=0;
for(int i=1;i<=ws(b);i++)//ws是位数
res=res*10+9;
if(b<res)
cout<<a*(ws(b)-1)<<endl;
else cout<<a*ws(b)<<endl;
}
}
signed main()
{
int t=1;
cin>>t;
while(t--)
{
solve();
}
}