Educational Codeforces Round 80. B - Yet Another Meme Problem

题面:https://codeforces.com/contest/1288/problem/B

题目大意:

令conc(a,b)函数得出的结果为将ab拼接得到的数字。

例如:conc(12,23)=1223

a和b不会包括前导0!

接下来,你已知A和B,问有多少对的(a,b)满足

1≤a≤A , 1≤b≤B

a*b+a+b=conc(a,b)

解题思路:

想法题,只需要满足b这个数字每一位全为9,那么等式 a*b+a+b=conc(a,b) 恒成立

因为 a*b+a+b=a*(b+1)+b

b+1为一个首位是1,其余位全为0的数,且长度为b的长度+1

所以a*(b+1)+b相当于a*(Length(b)+1)+b,即满足conc(a,b)的功能

故,只要计算1到B中有多少每一位全为9的数,再乘以A即可(a任取恒满足)

注意,最坏情况下a有1e9种,b有9种,最大的答案为9e9,超出int范围,必须用long long

 1 /*
 2 Written By. StelaYuri
 3 On 2020/01/14
 4 */
 5 #include<bits/stdc++.h>
 6 using namespace std;
 7 typedef long long ll;
 8 const ll mod=1000000007;
 9 bool isnine(ll in){
10     while(in){
11         if(in%10!=9)
12             return false;
13         in/=10;
14     }
15     return true;
16 }
17 int len(ll in){
18     int ans=0;
19     do{
20         in/=10;
21         ans++;
22     }while(in);
23     return ans;
24 }
25 int main(){
26     ios::sync_with_stdio(0);
27     cin.tie(0);cout.tie(0);
28     ll T,A,B,i,j,k;
29     cin>>T;
30     while(T--){
31         cin>>A>>B;
32         if(isnine(B))
33             cout<<A*len(B)<<endl;
34         else
35             cout<<A*(len(B)-1)<<endl;
36     }
37     
38     return 0;
39 }

猜你喜欢

转载自www.cnblogs.com/stelayuri/p/12221292.html