【题目链接】:http://codeforces.com/contest/822/problem/D

【题意】



有n个人参加选美比赛;

要求把这n个人分成若干个相同大小的组;

每个组内的人数是相同的;

然后每个组内的人,两两比较;

每个组得出最美的人;

然后每个组中最美的人再重复上述步骤;

直到只剩一个人;

问你如何选定每个阶段的分组;

使得比较的次数最少;

【题解】



只考虑一轮的情况;

设x是分组后每个组的人数;

然后一共有n个人;

则这一轮比较的次数就为

nx∗x∗(x−1)2

->n∗(x−1)2

这样看来x最小的时候效果最好;

则每个数字都取最小的因子就好;

这样设数字i的最小因子为p[i]

则设dp[i]表示i个人的时候最少需要多少次比较

dp[n]=dp[np[i]]+p[i]∗p[i−1]2∗np[i]

用筛法求出每个数的最小因子就好;

(最小因子都是质数吧.)



【Number Of WA】



0



【反思】



这种题做得比较少吧;

每一轮是独立的!

递推+贪心的方法;



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int INF = 5e6+10;
const LL MOD = 1e9+7; LL t,l,r;
LL p[INF],f[INF]; int main(){
//Open();
Close();
cin >> t >> l >> r;
rep1(i,1,(int) 5e6)
p[i] = i;
rep1(i,2,sqrt((int) 5e6)){
if (p[i]==i){
for (int k = i;k <= (int) 5e6;k+=i)
if (p[k]==k)
p[k] = i;
}
}
rep1(i,1,(int) 5e6 ){
f[i] = ((p[i]*(p[i]-1)/2)%MOD*(i/p[i])%MOD + f[i/p[i]])%MOD;
}
LL now = 1;
LL ans = 0;
rep1(i,(int)l,(int)r){
ans = (ans + now*f[i])%MOD;
now = (now*t)%MOD;
}
cout << ans << endl;
return 0;
}

【Codeforces Round #422 (Div. 2) D】My pretty girl Noora的更多相关文章

  1. 【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(二分写法)

    [题目链接]:http://codeforces.com/contest/822/problem/C [题意] 有n个旅行计划, 每个旅行计划以开始日期li,结束日期ri,以及花费金钱costi描述; ...

  2. 【Codeforces Round #422 (Div. 2) B】Crossword solving

    [题目链接]:http://codeforces.com/contest/822/problem/B [题意] 让你用s去匹配t,问你最少需要修改s中的多少个字符; 才能在t中匹配到s; [题解] O ...

  3. 【Codeforces Round #422 (Div. 2) A】I'm bored with life

    [题目链接]:http://codeforces.com/contest/822/problem/A [题意] 让你求a!和b!的gcd min(a,b)<=12 [题解] 哪个小就输出那个数的 ...

  4. 【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(hash写法)

    接上一篇文章; 这里直接把左端点和右端点映射到vector数组上; 映射一个open和close数组; 枚举1..2e5 如果open[i]内有安排; 则用那个安排和dp数组来更新答案; 更新答案完之 ...

  5. 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers

    [链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...

  6. 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes

    [题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...

  7. 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees

    [题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...

  8. 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

    [题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...

  9. 【Codeforces Round #423 (Div. 2) C】String Reconstruction

    [Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...

随机推荐

  1. UVa 1638 Pole Arrangement【递推】

    题意:给出n根高度为1,2,3,---n的杆子,从左边能看到l根,右边能够看到r根,问有多少种可能 看的紫书的思路 先假设已经安排好了高度为2---i的杆子, 那么高度为1的杆子的放置方法有三种情况 ...

  2. ActiveMQ服务安装

    1.下载安装ActiveMQ服务提供者 http://activemq.apache.org/ 2.启用ActiveMQ服务 cd [activemq_install_dir] bin\activem ...

  3. Mean, Median, Mode, Range, and Standard Deviation

    Descriptive statistics tell you about the distribution of data points in data set. The most common m ...

  4. Ubuntu 16.04 Chrome浏览器安装flash player插件

    1:官网下载插件  flash palyer lash_player_npapi_linux_debug.x86_64.tar.gz 2:解压 提取 libpepflashplayer.so 3:手动 ...

  5. Qt之水平/垂直布局(QBoxLayout、QHBoxLayout、QVBoxLayout)

    简述 QBoxLayout可以在水平方向或垂直方向上排列控件,由QHBoxLayout.QVBoxLayout所继承. QHBoxLayout:水平布局,在水平方向上排列控件,即:左右排列. QVBo ...

  6. 养活一款APP要“烧”多少钱?

    Duang!又一款APP刷爆朋友圈.大片范儿的电影截图.意味深长的经典对白均出自一款名为“足记”的APP. 足记团队刚于去年8月完成天使期融资,投资方是光速创投和紫辉创投,目前正准备A轮融资.且近一周 ...

  7. [AngularJS] ng-ture-value & ng-false-value

    When you have a checkbox, not necessary that just 'ture' & 'false', you might have 'yes', 'no', ...

  8. [React] Use React Fragments to make your DOM tree cleaner

    In this lesson, we will look at Fragments and how they are useful in achieving a cleaner DOM structu ...

  9. Unity3d 开发(七)AssetBundle组织文件夹

    本文探讨怎样配置一个AssetBundle更为合理. 对于结构为 的文件夹结构,当中shared是Hero文件夹下须要用到的公用资源.即公有依赖.可採用例如以下的打包策略 整个文件夹打包 将整个100 ...

  10. Android中的AsyncTask异步任务的简单实例

    在 Android中的AsyncTask异步任务的简介 一文中.已经对 安卓 异步任务操作做了简单的介绍.这里,直接将上文中的异步任务做了一个实例.实现异步操作更新UI线程,相比开启子线程更新来说逻辑 ...