#P8151. Fate and the Tarot Shuffle

    ID: 21333 Type: Default 1000ms 256MiB

Fate and the Tarot Shuffle

Fate and the Tarot Shuffle

In this problem, you are given an integer parameter defining decks of Tarot cards. For a positive integer n, consider a deck of 2^n cards with the initial order from bottom to top as [1, 2, 3, …, 2^n]. We define a shuffle operation S_1 on any sequence a = [a_1, a_2, …, a_{2^n}] as follows:

[ S_1(a) = [a_{2^{n-1}+1}, a_1, a_{2^{n-1}+2}, a_2, \dots, a_{2^n}, a_{2^{n-1}}]. ]

For any nonnegative integer q, define

[ S_q(a)=\begin{cases} a, & q=0,\ S_{q-1}(S_1(a)), & q\ge 1. \end{cases} ]

Now, for each n we define the function

[ f(n)=\sum_{q=0}^{n-1} \sum_{k=1}^{2^n} \left[ S_q([1,2,3,\dots,2^n])_k = k \right], ]

where ([P]) is 1 if the proposition P is true and 0 otherwise. In other words, for each q we count the number of fixed points (positions k such that the k-th card equals k) after applying q shuffles, and then sum these counts for q from 0 to n-1.

It turns out that the following closed‐form holds:

  • For even n:

    [ f(n) = 2^n, ]

  • For odd n:

    [ f(n) = 2^n + (n-1). ]

Your task is: given two positive integers l and r, compute the sum

[ \sum_{n=l}^{r} f(n). ]

Note: Use ( \LaTeX ) format for all formulas.

inputFormat

The input consists of a single line containing two space‐separated integers l and r (lr).

outputFormat

Output a single integer denoting \( \sum_{n=l}^{r} f(n) \).

sample

1 1
2