Educational Codeforces Round 6 B. Grandfather Dovlet’s calculator 暴力

B. Grandfather Dovlet’s calculator
 

Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators (https://en.wikipedia.org/wiki/Seven-segment_display).

Educational Codeforces Round 6 B. Grandfather Dovlet’s calculator 暴力

Max starts to type all the values from a to b. After typing each number Max resets the calculator. Find the total number of segments printed on the calculator.

For example if a = 1 and b = 3 then at first the calculator will print 2 segments, then — 5 segments and at last it will print 5 segments. So the total number of printed segments is 12.

Input

The only line contains two integers a, b (1 ≤ a ≤ b ≤ 106) — the first and the last number typed by Max.

Output

Print the only integer a — the total number of printed segments.

input
1 3
output
12
 
题意:
  给你0~9分别需要几根火柴拼成,现在 给定a,b,让你计算从a到b这个范围内 每一数位用到的火柴总和
题解:
  可以打表出10^6内每个数需要的火柴
  在计算~~~~~~~
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = ;
ll H[N][],a,b;
int M[] = {,,,,,,,,,};
int main() {
for(int i = ; i <= ; i++) {
int tmp = i;
while(tmp) H[i][tmp%]++,tmp/=;
}
ll ans = ;
scanf("%I64d%I64d",&a,&b);
for(int i = a; i <= b; i++) {
for(int j = ; j <= ; j ++) ans+= M[j] * H[i][j];
}
printf("%I64d\n",ans);
return ;
}
上一篇:Introduction and use of Cookie and Session(Cookie&Session的介绍和使用)


下一篇:Educational Codeforces Round 24 A 水 B stl C 暴力 D stl模拟 E 二分