【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 ...
随机推荐
- Java文件(io)编程——File类的基本用法
1.首先了解文件流的相关概念: 2.文件File类的基本用法 public class Demo_1 { public static void main(String[] args) { //创建一个 ...
- SLAM概念学习之特征图Feature Maps
特征图(或者叫地标图,landmark maps)利用参数化特征(如点和线)的全局位置来表示环境.如图1所示,机器人的外部环境被一些列参数化的特征,即二维坐标点表示.这些静态的地标点被观测器(装有传感 ...
- STM8S103之独立看门狗和窗口看门狗
独立看门狗时钟来源为LSI:窗口看门狗时钟来源为CPU: 窗口看门狗窗口的含义是:喂狗必须在一定的窗口期内完成,不能过早也不能过晚. 总结:防止程序复位,用独立看门狗. 独立看门狗使用的流程:参见库函 ...
- 数据库用varchar存储时间时会出现时间差解决办法
用varchar存储时间,最后提取数据库时间字段会出现时间差问题. 当我们调用数据库时间字段时,会出现时间差,使得查询的数据查询不到,解决办法如下 CAST( 字段名as DATE) between ...
- 字符串格式时间转Date格式
/** * 字符串时间格式转 Date 格式 * @param strDate * @return */ public static Date getDateTimeByStringTime(Stri ...
- kissy延迟加载demo
<!doctype html><html><head> <meta charset="gbk"/> <title& ...
- Linux命令之bc - 浮点计算器、进制转换
用途说明 Bash内置了对整数四则运算的支持,但是并不支持浮点运算,而bc命令可以很方便的进行浮点运算,当然整数运算也不再话下.手册页上说bc是An arbitrary precision calcu ...
- Python学习————字典的增删改查
增加:dic1['KEY'] = value -->若之前有KEY,则会覆盖.若没有KEY,则新增至尾处dic.setdefault('KEY',value/None) --->若之前有K ...
- 紫书 例题 11-12 UVa 1515 (最大流最小割)
这道题要分隔草和洞, 然后刘汝佳就想到了"割"(不知道他怎么想的, 反正我没想到) 然后就按照这个思路走, 网络流建模然后求最大流最小割. 分成两部分, S和草连, 洞和T连 外围 ...
- [TypeScript] Asynchronous Iteration using for-await-of
The for-await-of syntax is similar to the for-of iteration. The key difference is that it automatica ...