题目描述
Takahashi has come to an integer shop to buy an integer.
The shop sells the integers from 1 through 109. The integer N is sold for A×N+B×d(N) yen (the currency of Japan), where d(N) is the number of digits in the decimal notation of N.
Find the largest integer that Takahashi can buy when he has X yen. If no integer can be bought, print 0.
Constraints
·All values in input are integers.
·1≤A≤109
·1≤B≤109
·1≤X≤1018
输入
Input is given from Standard Input in the following format:
A B X
输出
Print the greatest integer that Takahashi can buy. If no integer can be bought, print 0.
样例输入 Copy
【样例1】
10 7 100
【样例2】
2 1 100000000000
【样例3】
1000000000 1000000000 100
【样例4】
1234 56789 314159265
样例输出 Copy
【样例1】
9
【样例2】
1000000000
【样例3】
0
【样例4】
254309
提示
样例1解释
The integer 9 is sold for 10×9+7×1=97 yen, and this is the greatest integer that can be bought. Some of the other integers are sold for the following prices:
·10:10×10+7×2=114 yen
·100:10×100+7×3=1021 yen
·12345:10×12345+7×5=123485 yen
样例2解释
He can buy the largest integer that is sold. Note that input may not fit into a 32-bit integer type.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,x;
bool check(ll m)
{
ll res=m;
ll len=0;
while(res)
{
len++;
res/=10;
}
if(a*m+b*len<=x) return 1;
else return 0;
}
int main()
{
cin>>a>>b>>x;
ll l=0,r=1e9;
while(l<r)
{
ll mid=l+r+1>>1;
if(check(mid)) l=mid;
else r=mid-1;
}
if(check(l)) cout<<l<<endl;
else cout<<0<<endl;
}