【Codeforces Round #422 (Div. 2) D】My pretty girl Noora
【题目链接】: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的更多相关文章
- 【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(二分写法)
[题目链接]:http://codeforces.com/contest/822/problem/C [题意] 有n个旅行计划, 每个旅行计划以开始日期li,结束日期ri,以及花费金钱costi描述; ...
- 【Codeforces Round #422 (Div. 2) B】Crossword solving
[题目链接]:http://codeforces.com/contest/822/problem/B [题意] 让你用s去匹配t,问你最少需要修改s中的多少个字符; 才能在t中匹配到s; [题解] O ...
- 【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 [题解] 哪个小就输出那个数的 ...
- 【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(hash写法)
接上一篇文章; 这里直接把左端点和右端点映射到vector数组上; 映射一个open和close数组; 枚举1..2e5 如果open[i]内有安排; 则用那个安排和dp数组来更新答案; 更新答案完之 ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
随机推荐
- STM8S103-STVD建立汇编代码项目
转载:http://blog.csdn.net/u010093140/article/details/49983397 STVD本来就比较少人用,STVD汇编就更少人用了,不过STM8汇编我自己还是满 ...
- frameset宽屏居中写法
在写frameset的时候发现页面较小的时候不能在屏幕上居中,记录一下frameset页面居中的写法 <frameset cols="*,1280,*" frameborde ...
- (转)JVM内存管理-----堆内存
来源:http://blog.csdn.net/yu422560654/article/details/7952613 Heap堆内存理解 一个JVM实例只有一个堆内存,堆内存的大小是可以调节的.类加 ...
- 利用MFC创建窗口、消息映射、window中的字节
利用MFC创建窗口: 1.mfc的头文件:afxwin.h 2.自定义类,继承于CWinApp,应用程序类(app应用程序对象,有且仅有一个) 3.程序入口:Initinstance 4.在程序入口中 ...
- 【CS-4476-project 6】Deep Learning
AlexNet / VGG-F network visualized by mNeuron. Project 6: Deep LearningIntroduction to Computer Visi ...
- adb如何连接mumu模拟器并修改Android ID
adb工具下载安装 https://dl.google.com/android/repository/platform-tools-latest-windows.zip 参考:https://blog ...
- Cause of 400 Bad Request Errors
The 400 Bad Request error displays inside the Internet browser window, just as web pages do. Cause o ...
- 【codeforces 816A】Karen and Morning
[题目链接]:http://codeforces.com/contest/816/problem/A [题意] 让你一分钟一分钟地累加时间; 问多长时间以后是个回文串; [题解] reverse之后如 ...
- jstack命令dump线程信息
jstack命令dump线程信息 D:\Java\jdk1.8.0_05\bin>jstack.exe 6540 > dump17 6540为java 线程pid: 出来的dump17文件 ...
- Cannot set web app root system property when WAR file is not expanded
Cannot set web app root system property when WAR file is not expanded 在tomcat下面可以,在weblogic下面不行的处理方法 ...