PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000092. Noora và số lần so sánh tối thiểu (My Pretty Girl Noora)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Noora và số lần so sánh tối thiểu (My Pretty Girl Noora)

My Pretty Girl Noora

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

In a selection contest with nn participants, every round with m>1m>1 participants chooses an integer x>1x>1 dividing mm, forms m/xm/x groups of exactly xx people, compares every pair within each group (x(x−1)/2x(x-1)/2 comparisons per group), then advances one person from each group. Repeat until one participant remains. Let f(n)f(n) be the minimum total number of comparisons. Given t,l,rt,l,r, calculate ∑n=lrtn−lf(n)\sum_{n=l}^{r}t^{n-l}f(n) modulo 109+710^9+7.

Input

One line contains three integers t,l,rt,l,r.

Output

Print the value of the expression modulo 109+710^9+7.

Subtasks

  • Subtask 1 (20 points): 1≤t≤10000000061\le t\le 1000000006; 2≤l≤r≤1002\le l\le r\le 100.
  • Subtask 2 (30 points): 1≤t≤10000000061\le t\le 1000000006; 2≤l≤r≤1000002\le l\le r\le 100000.
  • Subtask 3 (50 points): 1≤t≤10000000061\le t\le 1000000006; 2≤l≤r≤50000002\le l\le r\le 5000000.

Examples

Input

2 2 4

Output

19

Explanation

We have f(2)=1f(2)=1; f(3)=3f(3)=3 since three contestants must form one group; f(4)=3f(4)=3 by forming two pairs (two comparisons) then comparing the two winners (one more). For t=2,l=2,r=4t=2,l=2,r=4, the result is 1+2⋅3+22⋅3=1+6+12=191+2\cdot3+2^2\cdot3=1+6+12=19.