首页 > 其他分享 >Little Elephant and Interval

Little Elephant and Interval

时间:2024-11-09 11:51:02浏览次数:3  
标签:integers Little return int Interval Elephant pair

TF. Little Elephant and Interval

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.

Example

Input

2 47

Output

12

Note

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

code

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
 
using namespace std;


const int N = 510,INF=0x3f3f3f3f,mod=1e9+7;
 
typedef pair<int,int> PII;

int T=1;

int f(int x){
	if(x<10) return x;
	string str=to_string(x);
	if(str[0]>str[str.size()-1]) return x/10+8;
	else return x/10+9;
}

void solve(){
	int n,m;
	cin>>n>>m;
	cout<<f(m)-f(n-1)<<endl;
}

signed main(){
//	cin>>T; 
    while(T--){
        solve();
    }
    return 0;
}

标签:integers,Little,return,int,Interval,Elephant,pair
From: https://blog.csdn.net/2303_79062963/article/details/143530960

相关文章

  • [At_dp_w] Intervals & [At_dp_x] Tower
    两道题都很好Intervals给定\(m\)条规则形如\((l_i,r_i,a_i)\)​,对于一个01串,其分数的定义是:对于第\(i\)条规则,若该串在\([l_i,r_i]\)中至少有一个1,则该串的分数增加\(a_i\)你需要求出长度为\(n\)的01串中的最大分数\(1\len,m\le2\times10^5,|a_i|\le10^9\)......
  • Prometheus Alert Manager -- Difference between group_wait, group_interval, and r
    Definitiongroup_interval:group_interval dictateshowlongtowaitbeforesendingnotificationsaboutnewalertsthatareaddedtoagroupofalertsthathavebeenalertedonbefore。repeat_interval:IfthereisnothingchangeintheAlertGroup......
  • Interval GCD(单点修改线段树)
    细节不少//根据更相减损法gcd(x,y)=gcd(x,y-x)//推广到三项为gcd(x,y,z)=gcd(x,y-x,z-y)//可以推广到n项#include<bits/stdc++.h>usingnamespacestd;#definexfirst#defineysecondtypedefpair<int,int>PII;typedeflonglongll;typedefunsignedlonglong......
  • [算法] A LITTLE 网络流
    简介所谓网络流,就是给了一张图,有源点和汇点,让你求从源点放水,到汇点的水最多能有多少;这实际上是一个最大流的问题;最大流我们把这张图的每个边看作一条水管,每个水管都有一个容量,那么对于一条从源点到汇点的路径,其最大通过量是这些水管中容量最小的那一个的容量;对于这个问题,我们......
  • [算法] A LITTLE 计算几何
    叉积有两个平面向量a,b,那么有a$\times$b$=x_a\timesy_b-x_b\timesy_a$;这是有方向的,且遵守右手定则,正代表a逆时针转到b,负代表顺时针;凸包求凸包,我用的$Graham$扫描法;首先把最底下的点找出来,然后按照其它点对于这个点的角度排序,然后用一个类似于单调栈的......
  • 万象更新 Html5 - js: js 的 setInterval
    源码https://github.com/webabcd/Html5作者webabcd万象更新Html5-js:js的setInterval示例如下:js\setInterval.html<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>setInterval</ti......
  • js基础之setTimeout与setInterval原理分析
    setTimeout与setInterval概述setTimeout与setInterval是JavaScript引擎提供的两个定时器方法,分别用于函数的延时执行和循环调用。前者的主要思想是通过一个定时器,让函数在计时结束后再执行;后者则是每隔一定的时间,就启动一次函数的执行。从原理来看,两者似乎并不复杂。但由于JavaS......
  • SciTech-Mathmatics-Probability+Statistics-Population:Region-Sampling of Region :
    SciTech-Mathmatics-Probability+StatisticsPopulation:Region-SamplingofRegion:ConfidenceInterval(置信区间)置信区间的理解与应用在我们的统计学系列,已经探索了多个关键概念,从基本的统计学原理到更复杂的假设检验方法。在上一篇文章《统计学入门(三):假设检验的原理与应......
  • Efficient DevSecOps Workflows with a Little Help from AI
    EfficientDevSecOpsWorkflowswithaLittleHelpfromAIhttps://www.infoq.com/articles/efficient-devsecops-workflows/AIisenhancingDevSecOpsworkflowsbystreamliningtasks,improvingsecurity,andoptimizingoperations.UtilizeAIforgeneratingco......
  • Speaking-DailyLife little scar
          ......