CF822D.My pretty girl Noora

普及+/提高

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In Pavlopolis University where Noora studies it was decided to hold beauty contest "Miss Pavlopolis University". Let's describe the process of choosing the most beautiful girl in the university in more detail.

The contest is held in several stages. Suppose that exactly n girls participate in the competition initially. All the participants are divided into equal groups, x participants in each group. Furthermore the number x is chosen arbitrarily, i. e. on every stage number x can be different. Within each group the jury of the contest compares beauty of the girls in the format "each with each". In this way, if group consists of x girls, then comparisons occur. Then, from each group, the most beautiful participant is selected. Selected girls enter the next stage of the competition. Thus if n girls were divided into groups, x participants in each group, then exactly participants will enter the next stage. The contest continues until there is exactly one girl left who will be "Miss Pavlopolis University"

But for the jury this contest is a very tedious task. They would like to divide the girls into groups in each stage so that the total number of pairwise comparisons of the girls is as few as possible. Let f(n) be the minimal total number of comparisons that should be made to select the most beautiful participant, if we admit n girls to the first stage.

The organizers of the competition are insane. They give Noora three integers t, l and r and ask the poor girl to calculate the value of the following expression: _t_0·f(l) + _t_1·f(l + 1) + ... + t__r - l·f(r). However, since the value of this expression can be quite large the organizers ask her to calculate it modulo 109 + 7. If Noora can calculate the value of this expression the organizers promise her to help during the beauty contest. But the poor girl is not strong in mathematics, so she turned for help to Leha and he turned to you.

在诺拉就读的帕夫洛波利斯大学,校方决定举办“帕夫洛波利斯大学小姐”选美比赛。下面我们更详细地描述该大学选出最美女大学生的过程。

比赛分若干轮进行。假设最初恰好有 $ n $ 名女生参赛。所有参赛者被均分为若干组,每组 $ x $ 人。此外,每轮中 $ x $ 的取值可任意选定(即不同轮次中 $ x $ 的值可以不同)。在每组内部,评委以“两两比较”的方式对女生的美貌进行评判。因此,若某组包含 $ x $ 名女生,则该组内共发生

次比较。随后,从每组中选出最美的一位女生进入下一轮比赛。因此,若初始 $ n $ 名女生被分为每组 $ x $ 人的若干组,则恰好有

名女生进入下一轮。比赛持续进行,直至仅剩一名女生,她即被授予“帕夫洛波利斯大学小姐”称号。

然而,对评委而言,这项比赛任务极其繁重。他们希望在每轮中将女生分组的方式,使得女生之间总的两两比较次数尽可能少。记 $ f(n) $ 为:当第一轮有 $ n $ 名女生参赛时,为选出最美女生所需进行的最少总比较次数。

但本次比赛的组织者行为古怪。他们给诺拉三个整数 $ t 、、 l $ 和 $ r $,要求这位可怜的姑娘计算如下表达式的值:

t0⋅f(l)+t1⋅f(l+1)+⋯+tr−l⋅f(r).t_0 \cdot f(l) + t_1 \cdot f(l + 1) + \dots + t_{r - l} \cdot f(r).

然而,由于该表达式的值可能非常大,组织者要求她计算结果对 $ 10^9 + 7 $ 取模的值。若诺拉能算出该值,组织者便承诺在选美比赛中给予她帮助。但这位可怜的姑娘数学功底薄弱,于是向列哈求助;而列哈又转向了你。

输入格式

The first and single line contains three integers t, l and r (1 ≤ t < 109 + 7, 2 ≤ l ≤ r ≤ 5·106).

第一行且仅一行包含三个整数 tt、ll 和 rr(1 ≤ t < 109 + 71 ≤ t < 10^9 + 7,2 ≤ l ≤ r ≤ 5⋅1062 ≤ l ≤ r ≤ 5·10^6)。

输出格式

In the first line print single integer — the value of the expression modulo 109 + 7.

在第一行输出一个整数——该表达式的值对 109+710^9 + 7 取模的结果。

输入输出样例

  • 输入#1

    2 2 4

    输出#1

    19

说明/提示

Consider the sample.

It is necessary to find the value of .

f(2) = 1. From two girls you can form only one group of two people, in which there will be one comparison.

f(3) = 3. From three girls you can form only one group of three people, in which there will be three comparisons.

f(4) = 3. From four girls you can form two groups of two girls each. Then at the first stage there will be two comparisons, one in each of the two groups. In the second stage there will be two girls and there will be one comparison between them. Total 2 + 1 = 3 comparisons. You can also leave all girls in same group in the first stage. Then comparisons will occur. Obviously, it's better to split girls into groups in the first way.

Then the value of the expression is .

考虑该样例。

需要求出 的值。

f(2) = 1:从两名女生中只能组成一个两人小组,其中将进行一次比较。

f(3) = 3:从三名女生中只能组成一个三人小组,其中将进行三次比较。

f(4) = 3:从四名女生中可组成两个两人小组。那么第一阶段将进行两次比较(每个小组各一次);第二阶段剩下两名女生,将进行一次比较。总计 2 + 1 = 3 次比较。你也可以在第一阶段将所有女生保留在同一个小组中,此时将发生 次比较。显然,第一种分组方式更优。

因此,该表达式的值为 。

输入解题思路,AI测评打分。不知道怎么写?

首页