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<bits/stdc++.h>
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等等即可

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章