zcmu-2213:Reflection

Description

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

For each positive integer n consider the integer ψ(n) which is obtained from n by replacing every digit a in the decimal notation of n with the digit (9-a). We say that ψ(n) is the reflection of n. For example, reflection of 192 equals 807. Note that leading zeros (if any) should be omitted. So reflection of 9 equals 0, reflection of 91 equals 8.

Let us call the weight of the number the product of the number and its reflection. Thus, the weight of the number 10 is equal to 10·89=890.

Your task is to find the maximum weight of the numbers in the given range [l,r] (boundaries are included).

Input

Input contains two space-separated integers l and r (1≤lr≤109) − bounds of the range.

Output

Output should contain single integer number: maximum value of the product n·ψ(n), where lnr.

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d).

Examples

Input

3 7

Output

20

Input

1 1

Output

8

Input

8 10

Output

890

Note

In the third sample weight of 8 equals 8·1=8, weight of 9 equals 9·0=0, weight of 10 equals 890.

Thus, maximum value of the product is equal to 890.

题意就是在【l,r】区间内找x*(9...9-x)的最大值,按照位数一共九个二次函数开口朝下,最大值就是【4,5】,【49,50】,【499,500】。。。。判断区间是否包含这些点,若不包含则暴力跑一边r得到r的权值(为了保险比较了下l,r的值)

#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof a);
typedef long long ll;
ll _num[15]=
{
    20,
    2450,
    249500,
    24995000,
    2499950000,
    249999500000,
    24999995000000,
    2499999950000000,
    249999999500000000
};
int num[15];
ll  check(int a)
{
    int k=0;
    ll cou=0,tt=1;
    while(a)
    {
        num[k++]=9-a%10;
        a/=10;
    }
    for(int i=0; i<k; i++)
    {
        cou+=num[i]*tt;
        tt*=10;
    }
    return cou;
}
int main()
{
    int l,r;
    while(~scanf("%d %d",&l,&r))
    {
        if(l<=4&&r>=5&&r<=9) printf("%lld\n",_num[0]);
        else if(l<=49&&r>=50&&r<100) printf("%lld\n",_num[1]);
        else if(l<=499&&r>=500&&r<1000) printf("%lld\n",_num[2]);
        else if(l<=4999&&r>=5000&&r<10000) printf("%lld\n",_num[3]);
        else if(l<=49999&&r>=50000&&r<100000) printf("%lld\n",_num[4]);
        else if(l<=499999&&r>=500000&&r<1000000) printf("%lld\n",_num[5]);
        else if(l<=4999999&&r>=5000000&&r<10000000) printf("%lld\n",_num[6]);
        else if(l<=49999999&&r>=50000000&&r<100000000) printf("%lld\n",_num[7]);
        else if(l<=499999999&&r>=500000000&&r<1000000000) printf("%lld\n",_num[8]);
        else
        {
            ll x=check(l)*l,y=check(r)*r;
            printf("%lld\n",x>y?x:y);
        }
 
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值