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 ...
随机推荐
- 使用squid架设自己的代理server
主要參考了 http://blog.chinaunix.net/uid-20778906-id-540115.html Ubuntu下Squid代理server的安装与配置 1 安装 $ sudo a ...
- java开始到熟悉61
本此主题:多维数组----矩阵运算 矩阵的运算规则是将对应位置的值进行运算,如上图所示. package array; public class Matrix { /** * 打印矩阵 * @para ...
- Androidclient验证Licence的原理
需求 限制App的使用,使App仅仅能在有许可的设备上执行. 分析及解决方式 原理 让App在每次执行的时候都连接server进行合法性验证--当然是一个非常成熟可靠的方案. 可是这样做的局限也是每次 ...
- FastDFS的配置、部署与API使用解读(1)Get Started with FastDFS(转)
转载请注明来自:诗商·柳惊鸿CSDN博客,原文链接:FastDFS的配置.部署与API使用解读(1)入门使用教程 1.背景 FastDFS是一款开源的.分布式文件系统(Distributed File ...
- 移动GPU渲染原理的流派——IMR、TBR及TBDR
移动GPU渲染原理的流派--IMR.TBR及TBDR 移动GPU相对桌面级的GPU仅仅能算是未长大的小孩子,尽管小孩子在某些场合也能比成人更有优势(比方杂技.柔术之类的表演).但在力量上还是有先天的区 ...
- centos7+php7 swoole 安装
下载 swoole 首先下载swoole的源码包,这个操作很简单,没有太多说的. wget -c https://github.com/swoole/swoole-src/archive/v2.0.6 ...
- 正则工具类以及FinalClass
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/jadyer/article/details/27811103 完整版见https://jadyer. ...
- Parallels Desktop 设置win网络连接
目的: 1 虚拟机中的win系统技能访问外网 2 可以和Mac系统互联 首先来实现1,很简单: 打开控制中心对应系统的设置 选择[硬件]->[网络] 源:设置共享网络 到此就达到1目的了: 现在 ...
- HDU 5178 pairs —— 思维 + 二分
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5178 pairs Time Limit: 2000/1000 MS (Java/Others) ...
- javascript中基本类型和引用类型的区别分析
大多数人系统学习过的程序设计语言,在这些语言的学习过程中最早学到的几个要点之一就是值类型和引用类型的区别.下面我们来看一下在 JavaScript 中基本数据类型(Primitive Types)和引 ...