Chimeras
Time limit2sMemory limit1024 MB
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 years old can never have more than heads grow in place of any single cut head. Formally, assign each head a number called its generation. For a chimera that is years old, the following holds:
- At the start, the chimera has one head of generation 1.
- If you cut off a head of generation , where , then new heads of generation grow in its place.
- If you cut off a head of generation , nothing grows in its place.
The number of heads in generation is . Let be the total number of heads that must be cut off an -year-old chimera so that no new heads grow. For example, . Once all heads are cut off, the chimera dies. But if is divisible by its age , 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 years old, the oldest is years old, and for every integer with , there is a chimera of age in the forest. Each chimera whose age satisfies that is divisible by requires one magic arrow. Help Sir Petrein find how many arrows he needs to bring.
Input
The input file contains two integers and ().
Output
Output a single integer, the number of magic arrows Sir Petrein needs on his way to the Dark Lord's castle.