题目大意: 设 m a g i c ( x ) = magic(x)= magic(x)= 将 x x x 相邻两位做差的绝对值凑成的新数,设一个数的 m a g i c magic magic 指纹为不断嵌套 m a g i c magic magic 函数后最后的值,问有多少个数的 m a g i c magic magic 指纹为 7 7 7。
正解
前置芝士: 暴力做法
这个没有人不会的吧。
进阶
考虑神奇的分块~
回想以前分块统计答案的方法:将区间头尾部分的渣渣暴力求解,然后将中间的块们扫一遍,每次 O ( 1 ) O(1) O(1)提取这一整块的答案。
然而我们现在只能做到第一部分——求解渣渣。
那么精华来了,如何搞中间的块的答案呢?
线下暴力求解即可。
求出来之后,将他们一块一块的打包起来,使用即可。
造出来之后发现代码过长提交不了qwq
于是我们只能用线下的时间来换代码长度了——将块的规模扩大,这样块的个数就少了,需要记录的答案也就减少了。
AC代码在此:
#include <cstdio>
#include <cstring>
#define block 200000
#define belong(i) i/200000
int ans[5010]={772,249,114,249,661,512,106,43,39,344,272,225,67,48,138,76,133,72,51,25,30,107,88,69,22,22,69,88,107,30,25,51,72,133,76,138,48,67,225,272,344,39,43,106,512,
739,76,29,90,540,340,40,11,7,468,512,106,43,39,344,180,67,25,10,21,70,42,58,35,15,25,39,23,51,16,18,35,12,25,25,21,27,7,3,26,68,23,7,7,19,
227,28,10,4,78,528,18,10,5,366,121,81,18,10,148,332,88,16,8,114,272,225,67,48,138,55,83,47,23,13,21,81,31,59,12,16,51,23,39,25,21,42,14,6,35,
58,44,13,7,12,76,34,17,4,14,194,69,16,8,96,26,52,18,6,8,138,71,28,13,20,180,67,25,10,21,76,133,72,51,25,17,69,41,39,10,12,59,31,81,21,
16,39,29,20,64,25,32,25,10,36,23,31,18,9,8,14,21,19,12,9,7,37,24,14,3,38,31,35,13,9,163,40,57,17,21,55,83,47,23,13,30,107,88,69,22,
10,39,41,69,17,15,35,58,42,70,24,34,42,20,48,9,16,33,18,12,3,15,21,25,5,5,25,21,15,3,12,18,33,16,9,48,20,42,34,24,70,42,58,35,15,
17,69,41,39,10,22,69,88,107,30,13,23,47,83,55,21,17,57,40,163,9,13,35,31,38,3,14,24,37,7,9,12,19,21,14,8,9,18,31,23,36,10,25,32,25,
64,20,29,39,16,21,81,31,59,12,10,39,41,69,17,25,51,72,133,76,21,10,25,67,180,20,13,28,71,138,8,6,18,52,26,96,8,16,69,194,14,4,17,34,76,
12,7,13,44,58,35,6,14,42,21,25,39,23,51,16,12,59,31,81,21,13,23,47,83,55,138,48,67,225,272,114,8,16,88,332,148,10,18,81,121,366,5,10,18,528,
78,4,10,28,227,19,7,7,23,68,26,3,7,27,21,25,25,12,35,18,16,51,23,39,25,15,35,58,42,70,21,10,25,67,180,344,39,43,106,512,468,7,11,40,340,
1374,29,6,13,600,396,38,5,17,298,36,30,3,26,129,18,2,2,24,25,20,16,6,25,19,18,35,12,25,25,16,39,29,20,64,21,17,57,40,163,114,8,16,88,332,
739,76,29,90,540,198,14,1,0,413,332,88,16,8,114,59,26,22,7,4,17,17,22,11,14,6,16,10,12,7,3,7,5,12,6,1,2,2,2,12,3,1,2,2,22,
75,1,2,38,200,371,0,2,1,1087,340,40,11,7,468,512,106,43,39,344,180,67,25,10,21,70,42,58,35,15,25,39,23,51,16,18,35,12,25,25,21,27,7,3,26,
68,23,7,7,19,227,28,10,4,78,528,18,10,5,366,65,27,6,0,12,332,88,16,8,114,53,26,9,3,3,55,83,47,23,13,15,27,23,26,5,11,13,20,24,9,
8,7,11,6,16,7,3,6,6,10,6,0,4,4,12,10,0,2,3,45,18,35,13,3,5,138,71,28,13,20,53,34,24,3,2,25,15,13,8,5,7,36,18,31,3,
12,59,31,81,21,11,22,24,13,48,22,9,11,7,34,21,8,10,8,8,9,1,2,10,7,5,28,10,6,1,38,31,35,13,9,59,26,22,7,4,28,9,12,18,10,
9,15,4,17,5,6,28,10,17,15,4,22,23,37,27,24,34,42,20,48,8,11,19,10,9,2,10,8,21,2,3,19,11,9,2,12,18,33,16,9,42,15,23,21,7,
13,23,8,23,12,11,5,3,12,9,7,11,2,13,8,9,20,3,2,10,6,15,6,27,37,7,11,16,30,34,3,14,24,37,7,4,6,11,11,9,8,9,18,31,23,
12,6,22,18,11,17,17,22,11,14,6,6,9,5,8,7,4,2,2,8,9,7,2,3,9,6,9,3,2,1,14,11,6,12,37,8,2,14,17,26,12,1,6,8,109,
14,4,17,34,76,8,2,10,20,34,25,4,12,9,14,7,13,18,5,8,6,2,5,5,3,11,5,1,0,5,10,3,2,1,8,23,7,3,0,2,6,7,4,3,33,
122,1,3,12,351,78,4,10,28,227,7,2,5,18,43,24,1,6,19,11,6,16,10,12,7,3,0,9,8,4,8,0,1,3,1,18,1,0,0,9,96,7,2,0,67,
57,6,5,0,11,815,1,2,6,319,396,38,5,17,298,2,1,2,8,34,12,0,2,22,9,9,15,4,17,6,4,5,10,14,3,6,1,1,7,0,9,2,0,3,6,
108,3,1,39,78,453,5,1,1,464,96,24,2,0,118,174,39,10,2,15,163,40,57,17,21,48,13,24,22,11,8,24,7,22,8,6,17,4,15,9,3,6,2,2,15,
3,4,3,2,31,6,4,3,3,47,78,0,2,28,477,340,40,11,7,468,174,40,4,2,108,180,67,25,10,21,27,37,23,22,4,9,24,20,13,11,7,12,10,16,6,
5,5,7,2,16,2,2,5,5,11,10,1,4,4,43,130,0,1,4,240,121,81,18,10,148,332,88,16,8,114,272,225,67,48,138,55,83,47,23,13,21,81,31,59,12,
16,51,23,39,25,21,42,14,6,35,58,44,13,7,12,76,34,17,4,14,194,69,16,8,96,26,17,14,2,8,130,38,20,3,3,180,67,25,10,21,18,36,23,4,3,
17,69,41,39,10,5,26,23,27,15,14,11,22,17,17,15,5,8,8,13,14,3,3,5,7,7,0,1,9,8,5,25,5,11,1,34,30,16,11,7,163,40,57,17,21,
49,34,24,13,6,8,24,8,22,7,3,31,18,36,7,15,35,58,42,70,7,21,23,15,42,7,13,5,17,10,2,5,4,22,5,2,21,8,10,2,9,10,19,11,8,
48,20,42,34,24,27,37,23,22,4,15,17,10,28,6,5,17,4,15,9,10,18,12,9,28,4,7,22,26,59,9,13,35,31,38,1,6,10,28,5,6,8,14,6,14,
6,3,17,22,21,36,10,25,32,25,48,13,24,22,11,13,11,18,8,10,9,12,3,5,11,6,9,4,3,12,3,9,10,4,3,8,4,14,14,56,5,3,13,35,18,
13,2,15,2,124,8,0,7,11,71,12,7,13,44,58,28,4,8,19,17,9,24,20,13,11,8,5,9,6,6,9,10,2,1,5,6,4,4,2,7,9,6,8,1,2,
11,3,10,6,25,15,1,4,15,127,18,0,4,26,145,19,7,7,23,68,15,0,3,24,12,8,24,7,22,8,8,5,18,13,7,13,3,2,4,1,15,4,1,1,2,
13,8,3,1,10,20,4,5,3,5,176,1,4,11,119,173,0,2,7,133,36,30,3,26,129,9,0,2,8,16,17,9,4,21,7,7,12,10,16,6,8,1,3,10,0,
21,2,0,3,2,58,4,2,1,7,171,26,3,1,76,5,17,2,0,1,40,10,15,4,9,59,26,22,7,4,64,20,29,39,16,14,14,3,28,6,7,21,4,9,17,
7,11,2,0,15,4,9,3,3,8,0,6,1,0,7,3,1,4,1,5,213,37,3,0,129,42,28,3,3,16,53,34,24,3,2,70,42,58,35,15,12,37,11,28,13,
8,22,7,24,8,10,16,6,1,20,3,3,3,5,19,3,2,5,0,29,6,0,2,4,20,65,27,6,0,12,332,88,16,8,114,53,26,9,3,3,55,83,47,23,13,
15,27,23,26,5,11,13,20,24,9,8,7,11,6,16,7,3,6,6,10,6,0,4,4,12,10,0,2,3,45,26,52,18,6,8,138,71,28,13,20,180,67,25,10,21,
76,133,72,51,25,17,69,41,39,10,12,59,31,81,21,16,39,29,20,64,25,32,25,10,36,23,31,18,9,8,14,21,19,12,9,6,15,3,8,2,36,20,8,11,8,
59,26,22,7,4,55,83,47,23,13,2,28,19,12,3,10,39,41,69,17,4,22,23,37,27,21,25,12,20,31,9,10,2,11,10,2,5,3,13,4,5,22,4,5,2,
10,17,5,13,7,42,15,23,21,7,70,42,58,35,15,7,36,18,31,3,7,22,8,24,8,6,13,24,34,49,21,17,57,40,163,7,11,16,30,34,1,11,5,25,5,
5,12,7,1,10,7,4,14,7,22,12,6,22,18,11,64,20,29,39,16,15,27,23,26,5,6,28,10,17,15,6,10,9,13,21,5,8,18,16,18,3,3,20,38,130,
8,6,18,52,26,11,4,11,2,23,10,0,13,5,38,8,2,10,20,34,35,6,14,42,21,12,37,11,28,13,10,8,18,11,13,9,20,3,2,10,4,4,4,5,13,
7,5,15,2,18,18,0,14,12,94,3,2,6,4,17,8,0,8,12,32,7,2,5,18,43,26,3,7,27,21,14,14,3,28,6,11,13,20,24,9,15,9,5,16,7,
6,9,3,2,1,3,7,3,6,6,5,2,10,7,9,2,2,4,7,9,6,0,3,11,21,2,1,2,8,34,18,2,2,24,25,14,10,3,13,12,8,22,7,24,8,
13,9,10,19,5,11,6,1,10,6,23,7,3,0,2,2,6,2,4,2,3,14,4,2,0,18,2,15,5,7,37,27,6,15,6,48,13,24,22,11,25,25,12,35,18,
12,13,3,10,14,9,22,2,0,12,3,13,3,2,14,0,8,5,0,3,2,3,5,4,1,122,25,9,0,14,27,19,5,4,9,18,16,18,8,5,27,37,23,22,4,
25,39,23,51,16,6,28,3,14,14,11,19,6,1,24,6,8,7,2,9,3,5,9,0,15,5,0,2,4,9,121,81,18,10,148,174,39,10,2,15,49,11,10,3,6,
49,34,24,13,6,21,81,31,59,12,13,28,11,37,12,14,9,12,4,25,14,3,12,5,12,9,1,3,4,10,5,1,2,8,38,26,17,14,2,8,130,38,20,3,3,
180,67,25,10,21,18,36,23,4,3,17,69,41,39,10,5,26,23,27,15,14,11,22,17,17,15,5,8,8,13,14,3,3,5,7,7,0,1,9,8,7,37,24,14,3,
38,31,35,13,9,163,40,57,17,21,55,83,47,23,13,30,107,88,69,22,10,39,41,69,17,15,35,58,42,70,24,34,42,20,48,9,16,33,18,12,3,15,21,25,5,
4,13,3,5,2,10,11,2,10,9,31,20,12,25,21,27,37,23,22,4,17,69,41,39,10,3,12,19,28,2,13,23,47,83,55,4,7,22,26,59,8,11,8,20,36,
2,8,3,15,6,7,10,2,1,9,8,8,10,8,21,34,7,11,9,22,48,13,24,22,11,21,81,31,59,12,3,31,18,36,7,5,8,13,15,25,2,3,24,34,53,
20,13,28,71,138,5,3,13,35,18,7,4,7,2,21,9,2,9,6,23,8,2,13,10,45,28,4,8,19,17,25,39,23,51,16,5,26,23,27,15,10,18,12,9,28,
1,3,11,5,13,9,4,15,10,40,12,0,6,27,65,3,2,6,3,9,10,0,10,10,16,15,2,3,17,12,15,0,3,24,12,25,25,12,35,18,13,28,11,37,12,
12,23,8,23,13,3,9,10,4,3,2,6,5,7,3,5,2,10,13,22,0,2,5,5,3,3,0,1,12,6,2,1,2,25,23,9,0,2,8,16,20,16,6,25,19,
6,28,3,14,14,14,11,22,17,17,17,12,4,13,6,9,6,8,1,2,0,4,2,6,0,0,6,2,4,0,2,1,8,6,9,6,13,4,12,17,17,17,22,11,14,
14,14,3,28,6,19,25,6,16,20,16,8,2,0,9,23,25,2,1,2,6,12,1,0,3,3,5,5,2,0,22,13,10,2,5,3,7,5,6,2,3,4,10,9,3,
13,23,8,23,12,12,37,11,28,13,18,35,12,25,25,12,24,3,0,15,12,17,3,2,15,16,10,10,0,10,9,3,6,2,3,65,27,6,0,12,40,10,15,4,9,
13,5,11,3,1,28,9,12,18,10,15,27,23,26,5,16,51,23,39,25,17,19,8,4,28,45,10,13,2,8,23,6,9,2,9,21,2,7,4,7,18,35,13,3,5,
138,71,28,13,20,53,34,24,3,2,25,15,13,8,5,7,36,18,31,3,12,59,31,81,21,11,22,24,13,48,22,9,11,7,34,21,8,10,8,8,9,1,2,10,7,
6,15,3,8,2,36,20,8,11,8,59,26,22,7,4,55,83,47,23,13,2,28,19,12,3,10,39,41,69,17,4,22,23,37,27,21,25,12,20,31,9,10,2,11,10,
2,5,3,13,4,5,25,21,15,3,12,18,33,16,9,48,20,42,34,24,70,42,58,35,15,17,69,41,39,10,22,69,88,107,30,13,23,47,83,55,21,17,57,40,163,
9,13,35,31,38,3,14,24,37,7,8,9,1,0,7,7,5,3,3,14,13,8,8,5,15,17,17,22,11,14,15,27,23,26,5,10,39,41,69,17,3,4,23,36,18,
21,10,25,67,180,3,3,20,38,130,8,2,14,17,26,38,8,2,1,5,10,4,3,1,9,12,5,12,3,14,25,4,12,9,14,12,37,11,28,13,12,59,31,81,21,
6,13,24,34,49,6,3,10,11,49,15,2,10,39,174,148,10,18,81,121,9,4,2,0,5,15,0,9,5,3,9,2,7,8,6,24,1,6,19,11,14,14,3,28,6,
16,51,23,39,25,4,22,23,37,27,5,8,18,16,18,9,4,5,19,27,14,0,9,25,122,1,4,5,3,2,3,0,5,8,0,14,2,3,13,3,12,0,2,22,9,
14,10,3,13,12,18,35,12,25,25,11,22,24,13,48,6,15,6,27,37,7,5,15,2,18,0,2,4,14,3,2,4,2,6,2,2,0,3,7,23,6,10,1,6,11,
5,19,10,9,13,8,24,7,22,8,12,13,3,10,14,25,24,2,2,18,34,8,2,1,2,21,11,3,0,6,9,7,4,2,2,9,7,10,2,5,6,6,3,7,3,
1,2,3,9,6,7,16,5,9,15,9,24,20,13,11,6,28,3,14,14,21,27,7,3,26,43,18,5,2,7,32,12,8,0,8,17,4,6,2,3,94,12,14,0,18,
18,2,15,5,7,13,5,4,4,4,10,2,3,20,9,13,11,18,8,10,13,28,11,37,12,21,42,14,6,35,34,20,10,2,8,38,5,13,0,10,23,2,11,4,11,
26,52,18,6,8,130,38,20,3,3,18,16,18,8,5,21,13,9,10,6,15,17,10,28,6,5,26,23,27,15,16,39,29,20,64,11,18,22,6,12,22,7,14,4,7,
10,1,7,12,5,5,25,5,11,1,34,30,16,11,7,163,40,57,17,21,49,34,24,13,6,8,24,8,22,7,3,31,18,36,7,15,35,58,42,70,7,21,23,15,42,
7,13,5,17,10,2,5,4,22,5,4,13,3,5,2,10,11,2,10,9,31,20,12,25,21,27,37,23,22,4,17,69,41,39,10,3,12,19,28,2,13,23,47,83,55,
4,7,22,26,59,8,11,8,20,36,2,8,3,15,6,9,12,19,21,14,8,9,18,31,23,36,10,25,32,25,64,20,29,39,16,21,81,31,59,12,10,39,41,69,17,
25,51,72,133,76,21,10,25,67,180,20,13,28,71,138,8,6,18,52,26,45,3,2,0,10,12,4,4,0,6,10,6,6,3,7,16,6,11,7,8,9,24,20,13,11,
5,26,23,27,15,13,23,47,83,55,3,3,9,26,53,114,8,16,88,332,12,0,6,27,65,20,4,2,0,6,29,0,5,2,3,19,5,3,3,3,20,1,6,16,10,
8,24,7,22,8,13,28,11,37,12,15,35,58,42,70,2,3,24,34,53,16,3,3,28,42,129,0,3,37,213,5,1,4,1,3,7,0,1,6,0,8,3,3,9,4,
15,0,2,11,7,17,9,4,21,7,6,28,3,14,14,16,39,29,20,64,4,7,22,26,59,9,4,15,10,40,1,0,2,17,5,76,1,3,26,171,7,1,2,4,58,
2,3,0,2,21,0,10,3,1,8,6,16,10,12,7,7,21,4,9,17,16,8,2,0,9,129,26,3,30,36,133,7,2,0,173,119,11,4,1,176,5,3,5,4,20,
10,1,3,8,13,2,1,1,4,15,1,4,2,3,13,7,13,18,5,8,8,22,7,24,8,12,24,3,0,15,68,23,7,7,19,145,26,4,0,18,127,15,4,1,15,
25,6,10,3,11,2,1,8,6,9,7,2,4,4,6,5,1,2,10,9,6,6,9,5,8,11,13,20,24,9,17,19,8,4,28,58,44,13,7,12,71,11,7,0,8,
124,2,15,2,13,18,35,13,3,5,56,14,14,4,8,3,4,10,9,3,12,3,4,9,6,11,5,3,12,9,10,8,18,11,13,11,22,24,13,48,25,32,25,10,36,
21,22,17,3,6,14,6,14,8,6,5,28,10,6,1,38,31,35,13,9,59,26,22,7,4,28,9,12,18,10,9,15,4,17,5,6,28,10,17,15,4,22,23,37,27,
24,34,42,20,48,8,11,19,10,9,2,10,8,21,2,5,22,4,5,2,10,17,5,13,7,42,15,23,21,7,70,42,58,35,15,7,36,18,31,3,7,22,8,24,8,
6,13,24,34,49,21,17,57,40,163,7,11,16,30,34,1,11,5,25,5,8,9,1,0,7,7,5,3,3,14,13,8,8,5,15,17,17,22,11,14,15,27,23,26,5,
10,39,41,69,17,3,4,23,36,18,21,10,25,67,180,3,3,20,38,130,8,2,14,17,26,96,8,16,69,194,14,4,17,34,76,12,7,13,44,58,35,6,14,42,21,
25,39,23,51,16,12,59,31,81,21,13,23,47,83,55,138,48,67,225,272,114,8,16,88,332,148,10,18,81,121,240,4,1,0,130,43,4,4,1,10,11,5,5,2,2,
16,2,7,5,5,6,16,10,12,7,11,13,20,24,9,4,22,23,37,27,21,10,25,67,180,108,2,4,40,174,468,7,11,40,340,477,28,2,0,78,47,3,3,4,6,
31,2,3,4,3,15,2,2,6,3,9,15,4,17,6,8,22,7,24,8,11,22,24,13,48,21,17,57,40,163,15,2,10,39,174,118,0,2,24,96,464,1,1,5,453,
78,39,1,3,108,6,3,0,2,9,0,7,1,1,6,3,14,10,5,4,6,17,4,15,9,9,22,2,0,12,34,8,2,1,2,298,17,5,38,396,319,6,2,1,815,
11,0,5,6,57,67,0,2,7,96,9,0,0,1,18,1,3,1,0,8,4,8,9,0,3,7,12,10,16,6,11,19,6,1,24,43,18,5,2,7,227,28,10,4,78,
351,12,3,1,122,33,3,4,7,6,2,0,3,7,23,8,1,2,3,10,5,0,1,5,11,3,5,5,2,6,8,5,18,13,7,14,9,12,4,25,34,20,10,2,8,
76,34,17,4,14,109,8,6,1,12,26,17,14,2,8,37,12,6,11,14,1,2,3,9,6,9,3,2,7,9,8,2,2,4,7,8,5,9,6,6,14,11,22,17,17,
11,18,22,6,12,23,31,18,9,8,9,11,11,6,4,7,37,24,14,3,34,30,16,11,7,37,27,6,15,6,10,2,3,20,9,8,13,2,11,7,9,12,3,5,11,
12,23,8,23,13,7,21,23,15,42,9,16,33,18,12,2,9,11,19,3,2,21,8,10,2,9,10,19,11,8,48,20,42,34,24,27,37,23,22,4,15,17,10,28,6,
5,17,4,15,9,10,18,12,9,28,4,7,22,26,59,9,13,35,31,38,1,6,10,28,5,7,10,2,1,9,8,8,10,8,21,34,7,11,9,22,48,13,24,22,11,
21,81,31,59,12,3,31,18,36,7,5,8,13,15,25,2,3,24,34,53,20,13,28,71,138,5,3,13,35,18,45,3,2,0,10,12,4,4,0,6,10,6,6,3,7,
16,6,11,7,8,9,24,20,13,11,5,26,23,27,15,13,23,47,83,55,3,3,9,26,53,114,8,16,88,332,12,0,6,27,65,366,5,10,18,528,78,4,10,28,227,
19,7,7,23,68,26,3,7,27,21,25,25,12,35,18,16,51,23,39,25,15,35,58,42,70,21,10,25,67,180,344,39,43,106,512,468,7,11,40,340,1087,1,2,0,371,
200,38,2,1,75,22,2,2,1,3,12,2,2,2,1,6,12,5,7,3,7,12,10,16,6,14,11,22,17,17,4,7,22,26,59,114,8,16,88,332,413,0,1,14,198,
2939,39,1,3,585,742,1466,1,2,46,49,2,21,1,15,0,4,0,0,2,1,6,7,4,2,3,7,5,12,6,7,11,2,0,15,23,25,2,1,2,133,7,2,0,173,
600,13,6,29,1374,97,0,2,3,269,621,181,1,6,197,85,37,0,0,12,2,0,0,0,7,1,3,4,0,1,4,5,10,14,3,10,16,6,1,20,12,17,3,2,15,
145,26,4,0,18,528,18,10,5,366,3,1,3,8,42,7,1,2,4,58,13,18,1,3,49,3,1,0,1,9,2,2,3,1,3,3,0,9,8,4,8,7,11,6,16,
45,10,13,2,8,71,11,7,0,8,194,69,16,8,96,20,6,6,6,8,9,4,2,7,19,2,1,1,4,15,4,0,1,6,7,1,1,2,1,4,6,2,5,5,3,
13,9,10,19,5,22,9,11,7,34,21,22,17,3,6,14,21,19,12,9,5,28,10,6,1,36,20,8,11,8,6,13,4,12,17,5,1,2,10,9,3,5,1,7,5,
7,4,2,2,8,15,9,5,16,7,21,25,12,20,31,8,11,19,10,9,3,15,21,25,5,3,19,11,9,2,12,18,33,16,9,42,15,23,21,7,13,23,8,23,12,
11,5,3,12,9,7,11,2,13,8,9,20,3,2,10,6,15,6,27,37,7,11,16,30,34,3,14,24,37,7,5,12,7,1,10,7,4,14,7,22,12,6,22,18,11,
64,20,29,39,16,15,27,23,26,5,6,28,10,17,15,6,10,9,13,21,5,8,18,16,18,3,3,20,38,130,8,6,18,52,26,38,8,2,1,5,10,4,3,1,9,
12,5,12,3,14,25,4,12,9,14,12,37,11,28,13,12,59,31,81,21,6,13,24,34,49,6,3,10,11,49,15,2,10,39,174,148,10,18,81,121,240,4,1,0,130,
43,4,4,1,10,11,5,5,2,2,16,2,7,5,5,6,16,10,12,7,11,13,20,24,9,4,22,23,37,27,21,10,25,67,180,108,2,4,40,174,468,7,11,40,340,
1374,29,6,13,600,396,38,5,17,298,36,30,3,26,129,18,2,2,24,25,20,16,6,25,19,18,35,12,25,25,16,39,29,20,64,21,17,57,40,163,114,8,16,88,332,
739,76,29,90,540,0};
int aa[20],t;
int abs(int x){return x<0?-x:x;}
int solve(int x)//暴力求解部分
{
if(x<=9)return x;
t=0;
while(x>0)aa[++t]=x%10,x/=10;
int ne=0;
for(int i=t;i>=2;i--)
ne=ne*10+abs(aa[i]-aa[i-1]);
return solve(ne);
}
int a,b;
int anss=0;
int l(int x){return x*block+1;}//
int r(int x){return (x+1)*block-1;}
int main()
{
scanf("%d %d",&a,&b);
if(belong(a)==belong(b))
{
for(int i=a;i<=b;i++)
anss+=solve(i)==7;
printf("%d",anss);
return 0;
}
if(a!=l(belong(a)))
{
for(int i=a;i<=r(belong(a));i++)
anss+=solve(i)==7;
a=l(belong(a)+1);
}
if(b!=r(belong(b)))
{
for(int i=l(belong(b));i<=b;i++)
anss+=solve(i)==7;
b=r(belong(b)-1);
}
if(a<b)
{
for(int i=belong(a);i<=belong(b);i++)
anss+=ans[i];
}
printf("%d",anss);
}