Under construction

Still being built. Things may change

Chimeras

Time limit2sMemory limit1024 MB

Summary
Count the integers n in [a, b] for which 1! + 2! + ... + n! is divisible by n.
Level

Medium6 of 10

Topics
Math, Number theory
Solved
No attempts yet

Problem

Sir Petrein, a famous knight, was bored one gloomy autumn evening when he suddenly realized he had not visited his old friend, the Dark Lord, in a long time. The Dark Lord lives at the top of the Highest Tower in the Darkest Castle, thousands of versts away from ordinary people. That is not even the worst of it. The only way to reach the castle is along a long, narrow Dark Path through the Dark Forest, and the Dark Lord has placed some very unfriendly chimeras along it.

Sir Petrein knows the following about chimeras. A chimera has one head. If you cut off a head, two new heads grow in its place. If you then cut off those two, three new heads grow in place of each one, then four, and so on. However, a chimera that is nn years old can never have more than nn heads grow in place of any single cut head. Formally, assign each head a number called its generation. For a chimera that is nn years old, the following holds:

  • At the start, the chimera has one head of generation 1.
  • If you cut off a head of generation kk, where 1≤k<n1 \le k < n, then (k+1)(k + 1) new heads of generation k+1k + 1 grow in its place.
  • If you cut off a head of generation nn, nothing grows in its place.

The number of heads in generation kk is k!=1⋅2⋅…⋅kk! = 1 \cdot 2 \cdot \ldots \cdot k. Let S(n)S(n) be the total number of heads that must be cut off an nn-year-old chimera so that no new heads grow. For example, S(3)=9S(3) = 9. Once all S(n)S(n) heads are cut off, the chimera dies. But if S(n)S(n) is divisible by its age nn, the headless chimera turns into a huge fat troll. Nothing harms a troll except a magic arrow. So Sir Petrein must bring magic arrows just in case.

Sir Petrein knows that the chimeras in the forest have different ages. The youngest chimera is aa years old, the oldest is bb years old, and for every integer xx with a≤x≤ba \le x \le b, there is a chimera of age xx in the forest. Each chimera whose age nn satisfies that S(n)S(n) is divisible by nn requires one magic arrow. Help Sir Petrein find how many arrows he needs to bring.

Input

The input file contains two integers aa and bb (1≤a≤b≤10001 \le a \le b \le 1000).

Output

Output a single integer, the number of magic arrows Sir Petrein needs on his way to the Dark Lord's castle.

Examples2

  1. Example 1

    Input
    1 10
    
    Expected output
    3
    
  2. Example 2

    Input
    2 2
    
    Expected output
    0