Codeforces Round #422 (Div. 2) D - My pretty girl Noora

在Pavlopolis大学的选美比赛中,为了找出最少的比较次数来确定Miss Pavlopolis University,组织者引入了一个数学问题。他们希望在每轮比赛中将参赛者分成小组,使得总比较次数最小化。此问题被转化为一个数学函数f(n),表示如果有n名女孩参加比赛,选择最美女孩子的最少比较次数。Noora被要求计算一个表达式的值,该表达式涉及f(n)函数和一些给定参数。
D. My pretty girl Noora
time limit per test
1.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 tl and r and ask the poor girl to calculate the value of the following expression: tf(l) + tf(l + 1) + ... + tr - 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.

Input

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

Output

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

Example
input
2 2 4
output
19
Note

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 .

 

一开始的划分尽可能的小,比如6,先按2人一组再按3人一组,这样会比先按3人一组再按2人一组的比较次数要小。

线性筛记录每个数的最小因数,任意一个数的,如果为素数那么只能划分为一组,dp[i]=i*(i-1)/2;

否则dp[i]=i/最小因数 * dp[最小因数] + dp[i/最小因数]。

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#define ll long long
#define pb push_back
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define cls(name,x) memset(name,x,sizeof(name))
using namespace std;
const int inf=1e9+10;
const ll llinf=1e16+10;
const int maxn=5e6+10;
const int maxm=20;
const int mod=1e9+7;
const double pi=acos(-1.0);
ll t,l,r;
ll dp[maxn];
int fac[maxn];
bool prime[maxn];
void init()
{
    cls(prime,0);
    for(int i=2;i<maxn;i++)
        fac[i]=i;
    for(int i=2;i<maxn;i++)
    {
        if(prime[i]==0)
        {
            for(int j=2;i*j<maxn;j++)
            {
                fac[i*j]=min(fac[i*j],i);
                prime[i*j]=1;
            }
        }
    }
    for(ll i=2;i<maxn;i++)
    {
        if(prime[i])
            dp[i]=(dp[fac[i]]*(i/fac[i])+dp[i/fac[i]])%mod;
        else
            dp[i]=(i*(i-1)/2)%mod;
    }
}
int main()
{
    //freopen("in.txt","r",stdin);
    init();
    while(~scanf("%I64d %I64d %I64d",&t,&l,&r))
    {
        ll ans=0;
        ll k=1;
        for(int i=l;i<=r;i++)
        {
            ans=(ans+(k*dp[i])%mod)%mod;
            k=(k*t)%mod;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/mgz-/p/7112251.html

内容概要:本文档详细介绍了基于Cplex求解器的风光制氢合成氨系统优化研究,通过Matlab代码实现对这一复杂可再生能源系统的建模与优化分析。研究聚焦于风能、光伏等可再生能源耦合电解水制氢并进一步合成氨的综合能源系统,重点解决系统在容量配置与运行调度方面的协同优化问题。采用Cplex求解器进行高效的混合整数线性规划(MILP)求解,实现了对系统经济性、能效性、环境可持续性的多目标优化,涵盖设备选型与容量设计、能量流分配、运行策略制定、制氢与合成氨工艺集成等关键技术环节。该研究为高比例可再生能源消纳、绿氢规模化生产及绿色化工转型提供了重要的理论依据与可行的技术路径。; 适合人群:具备电力系统、能源系统、运筹学或化工过程系统工程等相关背景,熟悉Matlab编程与数学建模方法,从事新能源、氢能、综合能源系统、绿色化工等领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:① 学习并复现高水平学术论文中关于风光制氢合成氨系统的优化模型构建方法;② 掌握利用Cplex求解器解决复杂能源系统混合整数线性规划(MILP)问题的核心技术与实践流程;③ 为自身的科研项目或工程应用提供系统建模、优化算法实现与代码参考的坚实基础。; 阅读建议:学习者应结合所提供的Matlab代码与相关参考文献,深入剖析模型的物理意义、数学推导过程、约束条件的设定逻辑以及目标函数的设计思路,特别关注Cplex与Matlab的接口调用与数据传递机制,并建议通过调整关键参数(如可再生能源出力、设备效率、成本系数等)进行敏感性分析,以全面理解系统优化的内在机理与决策影响。
内容概要:本文系统研究了单相逆变器闭环控制下的PWM调制模型,基于Simulink平台构建完整的逆变电路仿真系统,涵盖主电路拓扑、闭环控制器设计、脉宽调制信号生成及输出滤波等关键环节。通过引入比例积分(PI)反馈控制策略,实现对输出电压幅值与波形的精确调节,有效抑制负载扰动带来的影响,提升系统的动态响应能力与稳态精度。仿真过程详细展示了系统建模、参数整定及性能验证的全流程,重点分析了闭环控制在改善输出正弦波质量、降低谐波畸变率方面的优势,为电力电子逆变装置的研发与优化提供了可靠的理论支撑与实践参考。; 适合人群:具备电力电子技术、自动控制原理基础知识及相关仿真经验的高校研究生、科研人员,以及从事新能源发电、不间断电源(UPS)、微电网、电动汽车等领域的工程技术人员。; 使用场景及目标:①掌握单相逆变器闭环控制系统的设计与建模方法;②深入理解PWM技术与反馈控制在逆变系统中的协同工作机制;③通过Simulink仿真平台完成系统搭建与参数调试,服务于课程设计、毕业课题、科研项目或工业产品开发中的逆变器控制算法验证。; 阅读建议:建议结合经典控制理论与电力电子变换技术同步学习,动手复现仿真模型并尝试调整PI控制器参数、载波频率等关键变量,观察其对系统稳定性与输出性能的影响,从而深化对控制机理的理解,并为进一步研究并网逆变、多电平逆变等复杂系统打下坚实基础。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值