codeforces 258C Little Elephant and LCM 组合数学 枚举
题意:
input :
n
a1,a2,...,an
1 <= n <= 10^5
1 <= ai <= 10^5
求b数组的方案数,b数组满足:
1. 1 <= bi <= ai
2. lcm(bi) = max(bi)
solution:
2说明了b数组的每一个元素都是max(bi)的约数
则:
1.sort a数组,ma = a[n]
2.预处理2个数组,vector<int> dive[MAXN],int pos[MAXN]
dive[i]保存i的约数,并且按照小到大排序
sort(dive[i].begin(),dive[i].end())
pos[i]表示a数组中 >= i 的数的最小位置
3.枚举max(bi):1~ma,则:
ans = sigma( dive(i).size()^(n - pos[i]+1) - (dive[i].size()-1)^(n-pos[i]+1) *
sigma((j+1)^(pos[dive[i][j+1]])-pos[dive[i][j]]),0<=j<dive[i].size() ),1<=i<=ma
推这条公式其实就是枚举max为i,然后把b数组分成若干段,每一个段的可以选择的数就是dive[i]的部分约数,先把dive[i]排序后,可以知道每一个段可以选择的数的个数,就得到公式了。
//File Name: cf258C.cpp
//Author: long
//Mail: 736726758@qq.com
//Created Time: 2016年02月23日 星期二 18时30分26秒 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <map> #define LL long long
#define pb push_back using namespace std; const int MAXN = (int)1e5+;
const int MOD = (int)1e9+; int a[MAXN];
vector<int> dive[MAXN];
int pos[MAXN];
int ma; LL qp(LL x,LL y)
{
LL res = 1LL;
while(y){
if(y & )
res = res * x % MOD;
x = x * x % MOD;
y >>= ;
}
return res;
} void get_dive(int x)
{
for(int i=;i<=x;i++){
dive[i].clear();
int e = (int)sqrt(i + 0.0);
for(int j=;j<=e;j++){
if(i % j == ){
dive[i].pb(j);
if((i / j) != j)
dive[i].pb(i / j);
}
}
sort(dive[i].begin(),dive[i].end());
}
} int bs(int l,int r,int x)
{
int mid;
while(r - l > ){
mid = (l + r) >> ;
if(a[mid] < x)
l = mid;
else
r = mid;
}
if(a[l] >= x)
return l;
return r;
} void solve(int n)
{
sort(a+,a+n+);
ma = a[n];
get_dive(ma);
pos[] = ;
for(int i=;i<=ma;i++){
pos[i] = bs(pos[i-],n,i);
}
LL ans = 0LL;
LL tmp;
for(int i=;i<=ma;i++){
int x = n - pos[i] + ;
int y = (int)dive[i].size();
tmp = (qp(y,x) - qp(y-,x) + MOD) % MOD;
for(int j=;j<dive[i].size() - ;j++){
tmp = tmp * qp(j+,pos[dive[i][j+]] - pos[dive[i][j]]) % MOD;
}
ans = (ans + tmp) % MOD;
}
printf("%d\n",(int)ans);
return ;
} int main()
{
int n;
while(~scanf("%d",&n)){
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
solve(n);
}
return ;
}
codeforces 258C Little Elephant and LCM 组合数学 枚举的更多相关文章
- Codeforces 258C Little Elephant and LCM
Little Elephant and LCM #include<bits/stdc++.h> #define LL long long #define fi first #define ...
- CodeForces - 204C Little Elephant and Furik and Rubik
CodeForces - 204C Little Elephant and Furik and Rubik 个人感觉是很好的一道题 这道题乍一看我们无从下手,那我们就先想想怎么打暴力 暴力还不简单?枚 ...
- Codeforces D. Little Elephant and Interval(思维找规律数位dp)
题目描述: Little Elephant and Interval time limit per test 2 seconds memory limit per test 256 megabytes ...
- Codeforces 1264D - Beautiful Bracket Sequence(组合数学)
Codeforces 题面传送门 & 洛谷题面传送门 首先对于这样的题目,我们应先考虑如何计算一个括号序列 \(s\) 的权值.一件非常显然的事情是,在深度最深的.是原括号序列的子序列的括号序 ...
- CodeForces 259A Little Elephant and Chess
Little Elephant and Chess Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d &am ...
- Codeforces 204A Little Elephant and Interval
http://codeforces.com/problemset/problem/204/A 题意:给定一个[L,R]区间,求这个区间里面首位和末尾相同的数字有多少个 思路:考虑这个问题满足区间加减, ...
- Codeforces 429B Working out:dp【枚举交点】
题目链接:http://codeforces.com/problemset/problem/429/B 题意: 给你一个n*m的网格,每个格子上有一个数字a[i][j]. 一个人从左上角走到右下角,一 ...
- [Codeforces 204E] Little Elephant and Strings
[题目链接] https://codeforces.com/contest/204/problem/E [算法] 首先构建广义后缀自动机 对于自动机上的每个节点 , 维护一棵平衡树存储所有它所匹配的字 ...
- Codeforces Gym 100431B Binary Search 搜索+组合数学+高精度
原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-an ...
随机推荐
- phpmyadmin导入导出大数据文件的办法
在phpmyadmin的使用中,经常需要进行导入导出数据库的操作. 但是在导入导出大型数据库文件的时候经常会只是部分导出或者部分导入. 或者是导入导出不成功. 原因就是服务器和php.mysql限制了 ...
- const 常引用
常类型是指使用类型修饰符 const 说明的类型,常类型的变量或对象的值是不能被更新的. 这篇主要说常引用.常引用是指所引用的对象不能被更新. 在实际应用中,常引用往往用来作为函数的形参,这样的参数称 ...
- 搭建最简单的SpringMVC框架(使用maven)
本文说明:本文介绍使用maven搭建SpringMVC最简单的框架程序过程,适合初学者上手. 下载链接 点此进入下载链接 1.创建一个maven webapp工程. 2.修改WEB-INF目录下的we ...
- .net 开源相关
http://roslyn.codeplex.com/SourceControl/latest https://github.com/dotnet http://www.dotnetfoundatio ...
- VS产生sdf和ipch文件太大处理方案
方法: 工具-->选项-->文本编辑器-->C/C++-->高级-->回退位置,把始终使用回退位置设置为true,回退位置已在使用,不警告也设置为true,回退位置设置为 ...
- OAuth2.0详解
1.使用场景 A系统存放着订单信息 B系统需要查询A系统中的订单信息,但是必须要A系统验证通过后,才能查询. 此时,我们有两种验证方式: 1)拥有A系统的账户/密码 弊端是对A系统来说,直接提供账户/ ...
- 如何使用投影看着备注分享自己的PPT
1. 设置多屏幕 一般你的笔记本就是1, 投影是2 2. 设置幻灯片的放映方式 设置幻灯片显示于另外一个监视器 并勾选显示演示者视图 3. 点击放映 就会出现 左上角是ppt本身, 右上角是 ...
- python_Memcached
一.Memcached 1.Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网 ...
- python exec
exec官方声明This statement supports dynamic execution of Python code. exec语句用来执行储存在字符串或文件中的python语句.exec ...
- MySQL explain key_len 大小的计算
总结: 变长字段需要额外的2个字节,固定长度字段不需要额外的字节.而null都需要1个字节的额外空间,所以以前有个说法:索引字段最好不要为NULL,因为NULL让统计更加复杂,并且需要额外一个字节的存 ...