Little Elephant and Interval

Little Elephant and Interval
Time Limit:2000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u

Description

The Little Elephant very much loves sums on intervals.

This time he has a pair of integers l and r(l ≤ r). The Little Elephant has to find the number of such integers x(l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.

Help him and count the number of described numbers x for a given pair l and r.

Input

The single line contains a pair of integers l and r(1 ≤ l ≤ r ≤ 1018) — the boundaries of the interval.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

Output

On a single line print a single integer — the answer to the problem.

Sample Input

Input
2 47
Output
12
Input
47 1024
Output
98

Hint

In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.


意思就只求区间内M ~ N内的首尾和末位数字相同的个数

任然采用0~N区间的数字 减去 0~M 区间的数字个数

对于数字N ,如果小于10,然么直接返回。 要不然返回首尾的数字加上9.而且要注意当首尾大于末位的时候,需要减一

举个例子:46这个数。一共有1~9 加上11,22,33,44.这4个数一共13个数符合题目要求,正好是n / 10 + 9.

当数字为43时,首尾大于末位,44这样的数字就不符合要求了。所以当首尾大于末位时需要sum--;

/***********************************************
 * Author: fisty
 * Created Time: 2015/2/8 20:47:21
 * File Name   : 6_D.cpp
 *********************************************** */
#include <iostream>
#include <cstring>
#include <deque>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <algorithm>
using namespace std;
#define Debug(x) cout << #x << " " << x <<endl
#define Memset(x, a) memset(x, a, sizeof(x))
const int INF = 0x3f3f3f3f;
typedef long long LL;
typedef pair<int, int> P;
#define FOR(i, a, b) for(int i = a;i < b; i++)
LL solve(LL n){
    LL sum = 0;
    if(n < 10) return n;
    else{
        int r = n % 10;
        sum = n / 10 + 9;
        while(n >= 10) n /= 10;
        //Debug(sum);
        if(n > r) sum--;
    } 
    //Debug(sum);
    return sum;
}
int main(){
    //freopen("in.cpp", "r", stdin);
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    LL l, r;
    cin >> r >> l;
    
    cout << solve(l) - solve(r-1) << endl;
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值