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 ...
随机推荐
- time is always a factor, time is always now!!!!
https://www.linkedin.com/pulse/time-always-now-joe-alderman ---------------------------------------- ...
- 【转】How to Change File Ownership & Groups in Linux
有关linux下 文件权限的问题,一直不是很清楚.(参考菜鸟教程: http://www.runoob.com/linux/linux-file-attr-permission.html) 像上面这样 ...
- zedboard中OLED源码
#include <stdio.h> #include "platform.h" #include "xil_types.h" #include & ...
- NOI 2014简要题解
Day 1.Problem A. 起床困难综合症 100分做法: 把数字看成二进制数.对于初始攻击力.我们将其拆成32位,并求出每一位为0和1时经过全部防御门之后分别得到的数字.然后就是按位贪心了,我 ...
- ok6410[000] 搭建裸机开发环境
1.安装交叉工具链arm-linux-gcc-4.3.2 先把这个工具复制到rhat系统中[rhel-server-6.3-i386-dvd.iso] 解压arm-linux-gcc-4.3.2到一个 ...
- ActionFilterAttribute之HtmlFilter,压缩HTML代码
当开启这个过滤器后,最终生成的HTML代码将会被压缩一下,在流量很大的网站中,能减少带宽成本就减少一点,何乐而不为? [csharp] view plaincopy using System; usi ...
- Lily HBase Indexer同步HBase二级索引到Solr丢失数据的问题分析
一.问题描述二.分析步骤2.1 查看日志2.2 修改Solr的硬提交2.3 寻求StackOverFlow帮助2.4 修改了read-row="never"后,丢失部分字段2.5 ...
- SpringMVC 学习笔记(四) 处理模型数据
Spring MVC 提供了下面几种途径输出模型数据: – ModelAndView: 处理方法返回值类型为 ModelAndView时, 方法体就可以通过该对象加入模型数据 – Map及Model: ...
- spring boot 使用Ehcache
1-引入maven依赖: 2-增加ehcache.xml 3-bootstrap.yml配置ehcache.xml的路径 4-启动类加注解@EnableCaching 5-使用处加注解@Cacheab ...
- centreon问题总结
1.SNMP TABLE ERROR : Requested table is empty or does not exist 这是SNMP的服务端查询客服端失败,失败的原理是权限不足 解决办法: v ...