codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

121A.md (1401B)


      1 Source: https://codeforces.com/problemset/problem/121/A
      2 
      3 A. Lucky Sum
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
     22 
     23 Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested what is the value of the expression *next*(*l*) + *next*(*l* + 1) + ... + *next*(*r* - 1) + *next*(*r*). Help him solve this problem.
     24 
     25 Input
     26 
     27 The single line contains two integers *l* and *r* (1 ≤ *l* ≤ *r* ≤ 109) — the left and right interval limits.
     28 
     29 Output
     30 
     31 In the single line print the only number — the sum *next*(*l*) + *next*(*l* + 1) + ... + *next*(*r* - 1) + *next*(*r*).
     32 
     33 Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.
     34 
     35 Examples
     36 
     37 Input
     38 
     39 ```
     40 2 7
     41 ```
     42 
     43 Output
     44 
     45 ```
     46 33
     47 ```
     48 
     49 Input
     50 
     51 ```
     52 7 7
     53 ```
     54 
     55 Output
     56 
     57 ```
     58 7
     59 ```
     60 
     61 Note
     62 
     63 In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33
     64 
     65 In the second sample: *next*(7) = 7