Codeforces Round #422 (Div. 2)D. My pretty girl Noora(递推+数论)
传送门
题意
对于n个女孩,每次分成x人/组,每组比较次数为\(\frac{x(x+1)}{2}\),直到剩余1人
计算$$\sum_{i=l}{r}t{i-l}f(i)$$,其中f(i)代表i个女孩的最少比较数
分析
难度在于如何计算f(i),f(i)每次除的是素数,详情见题解
那么我们对于每一个素数i,直接计算\(f[i]=\frac{x(x+1)}{2}\)
非素数,枚举能被i整除的第一个素数j,\(f[i]=f[i/j]+i*(j-1)/2\)
-end-
trick
代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))
//#pragma comment(linker, "/STACK:102400000,102400000")
//inline void read(int &x){x=0; char ch=getchar();while(ch<'0') ch=getchar();while(ch>='0'){x=x*10+ch-48; ch=getchar();}}
const int maxn=5e6;
const ll mod = 1e9+7;
int prime[maxn+100];
bool p[maxn+100];
void get_prime()
{
F(i,2,maxn)
{
if(!p[i]) prime[++prime[0]]=i;
for(int j=1;j<=prime[0]&&i*prime[j]<=maxn;++j)
{
p[i*prime[j]]=1;
if(i%prime[j]==0) break;
}
}
}
ll t;
int l,r;
ll f[maxn+100],ans;
int main()
{
get_prime();
//F(i,1,prime[0]) f[prime[i]]=(ll)prime[i]*(ll)(prime[i]-1)/2;
scanf("%lld %d %d",&t,&l,&r);
//F(i,1,100) printf("%d\n",p[i]);
f[1]=1;
for(int i=2;i<=maxn;++i)if(p[i])
{
for(int j=1;j<=prime[0];++j) if(i%prime[j]==0) {f[i]=1LL*i*(prime[j]-1)/2+f[i/prime[j]];break;}
}
else {f[i]=1LL*i*(i-1)/2%mod;};
ll cnt=1;
F(i,l,r)
{
ans=(ans+cnt*f[i])%mod;
cnt=cnt*t%mod;
}
printf("%I64d\n",ans);
return 0;
}
Codeforces Round #422 (Div. 2)D. My pretty girl Noora(递推+数论)的更多相关文章
- Codeforces Round #422 (Div. 2) D. My pretty girl Noora 数学
D. My pretty girl Noora In Pavlopolis University where Noora studies it was decided to hold beau ...
- Codeforces Round #422 (Div. 2)
Codeforces Round #422 (Div. 2) Table of Contents Codeforces Round #422 (Div. 2)Problem A. I'm bored ...
- 【Codeforces Round #422 (Div. 2) D】My pretty girl Noora
[题目链接]:http://codeforces.com/contest/822/problem/D [题意] 有n个人参加选美比赛; 要求把这n个人分成若干个相同大小的组; 每个组内的人数是相同的; ...
- 【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)E. Liar sa+st表+dp
题意:给你两个串s,p,问你把s分开顺序不变,能不能用最多k段合成p. 题解:dp[i][j]表示s到了前i项,用了j段的最多能合成p的前缀是哪里,那么转移就是两种,\(dp[i+1][j]=dp[i ...
- Codeforces Round #422 (Div. 2) E. Liar 后缀数组+RMQ+DP
E. Liar The first semester ended. You know, after the end of the first semester the holidays beg ...
- Codeforces Round #422 (Div. 2) C. Hacker, pack your bags! 排序,贪心
C. Hacker, pack your bags! It's well known that the best way to distract from something is to do ...
随机推荐
- HDU 1003 Max Sum (动规)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- Effective C++ 条款四 确定对象被使用前已被初始化
1.对于某些array不保证其内容被初始化,而vector(来自STL)却有此保证. 2.永远在使用对象前初始化.对于无任何成员的内置类型,必须手工完成. int x = 0; c ...
- 作为iOS程序员,最核心的60%能力有哪些?
作为iOS程序员,最核心的60%能力有哪些? 一个合格的iOS程序员需要掌握多少核心技能?你和专业的开发工程师的差距有多大?你现在的水平能开发一个功能完整性能高效的iOS APP吗?一起来看看下面 ...
- 继承LinearLayout实现根据屏幕宽度及内部子View个数自动排布GridView
public class VerticalSearchGridView extends LinearLayout implements View.OnClickListener { private i ...
- De Moivre–Laplace theorem 掷硬币
De Moivre–Laplace theorem - Wikipedia https://en.wikipedia.org/wiki/De_Moivre%E2%80%93Laplace_theore ...
- sqlldr trailing nullcols
由于要导入到tmp_content表的一些列(列:要导入的源文件txt or csv文件)为空,也,按理讲我当时另存为(在windows处理)csv,以,分隔.就是这个列没有内容,也该显示, ,之类的 ...
- 20170225-第一件事:SAP模块清单
第一件事:SAP模块清单 AM 资产会计 资产会计BC SAP Netweaver SAP NetweaverBW 业务信息仓库 业务信息仓库CA 常规跨应用程序 常规跨越应用程序CO 控制 控制 C ...
- Java DES加密解密
import javax.crypto.Cipher; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESKeySpe ...
- android adb 源码框架分析(2 角色)【转】
本文转载自:http://blog.csdn.net/luansxx/article/details/25203323 角色 l 服务 服务是提供特定功能的实体,接收请求,返回应答是服务直接最表现. ...
- nginx最简单的网站配置:单主机+静态文件
1.域名绑定主机:新建一个A记录,将www的子域名绑定到主机的ip上:2.主机的nginx设置监听端口,绑定域名,修改网站根目录路径和默认首选文件:/etc/nginx/conf.d 这个目录中新建一 ...