cf Educational Codeforces Round 80 B. Yet Another Meme Problem

原题:

B. Yet Another Meme Problem
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Try guessing the statement from this picture http://tiny.cc/ogyoiz.

You are given two integers A and B, calculate the number of pairs (a,b) such that 1≤a≤A, 1≤b≤B, and the equation a⋅b+a+b=conc(a,b) is true; conc(a,b) is the concatenation of a and b (for example, conc(12,23)=1223, conc(100,11)=10011). a and b

should not contain leading zeroes.
Input

The first line contains t (1≤t≤100) — the number of test cases.

Each test case contains two integers A and B (1≤A,B≤109)

.
Output

Print one integer — the number of pairs (a,b) such that 1≤a≤A, 1≤b≤B, and the equation a⋅b+a+b=conc(a,b) is true.

Example
Input
3
1 11
4 2
191 31415926

Output

1
0
1337

Note

There is only one suitable pair in the first test case: a=1
, b=9 (1+9+1⋅9=19).

中文:

给你两个数A,B,现在让你找出所有满足,1<= a <= A 且 1<=b <=B ,使得a*b + a +b = con(a,b),这里con表示将a和b转换成字符串连接起来。

代码:

#include
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
 
int main()
{
    ios::sync_with_stdio(false);
    ll t,a,b;
    cin>>t;
    while(t--)
    {
        cin>>a>>b;
        b++;
        if(b<9)
        {
            cout<<0<<endl;
            continue;
        }
        ll rig = to_string(b).size()-1;
        ll ans= a*rig;
        cout<<ans<<endl;
    }
    return 0;
}
 
 

解答:

这B题还挺有意思,一般这样的题目都有点规律,可以先暴力枚举前1000个数看看结果就知道是什么情况了。
当然,从问题推到出结论还是根本任务。

如果满足ab + a + b = con(a,b),那么一定又ab+a+b=a*10^len(b) + b,其中len(b)表示b作为字符串的长度,花间一下可以得到
b+1 = 10^len(b),那么保证b是9,或99或者999等等即可

你可能感兴趣的:(数学,算法)