report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Balanced number - MarisaOJ: Marisa Online Judge

Balanced number

Time limit: 1000 ms
Memory limit: 256 MB
Given an integer $x$ with $m$ digits, denote $d_i$ as the $i$-th digit from left to right of this integer. If we choose a digit at position $p$ such that $1 \le p \le m$ as the center of this number, the weight on the left side is: $ \sum_{i=1}^{p-1} d_i \times (p - i) $ and similarly, the weight on the right side is: $ \sum_{i=p+1}^{m} d_i \times (i - p) $ A number is considered balanced if there exists a position $p$ such that the weight on the left side is equal to the weight on the right side. Count the number of balanced integers in the range $[a, b]$. ### Input - A single line containing two integers $a, b$. ### Output - Print an integer representing the number of balanced integers in the range $[a, b]$. ### Constraints - $1 \le a \le b \le 10^{18}$ ### Example Input: ``` 7604 24324 ``` Output: ``` 897 ```
Digit DP
Unlucky number
Digit Sum
Divisible
Prime digit sum
Non-palindrome number
Yet another XOR problem
Taboo substring
Balanced number
Equation
Beautiful number
Constructing numbers
Topic
Dynamic Programming
Rating 1700
Source HDU
Solution (1) Solution