CF1174E Ehab and the Expected GCD Problem(动规+数论+分解)
做法
先来填第一个数,为了保证\(f(p)\)最大,第一个数分解一下为\(\prod\limits_{p_i}p_i^{k_i}\)使得\(\sum\limits_{k_i}\)最大
显然第一个数为\(2^x3^y\)且\(y≤1\),否则可以把\(3^2\)换成\(2^3\),故第一个数最多有两种选择
定义函数\(Cout(x,y)=\frac{n}{2^x3^y}\)为n以内含因子\(2^x3^y\)的个数
设\(f_{i,x,y}\)为填到第\(i\)个数后\(gcd_{j=1}^i a_i=2^x3^y\)的方案数,显然最后的答案为\(f_{n,0,0}\)
code
#include<bits/stdc++.h>
using namespace std;
typedef int LL;
const LL maxn=1e6+9,mod=1e9+7;
LL n;
LL f[maxn][21][2];
inline LL Pow(LL base,LL b){
LL ret(1);
while(b){
if(b&1) ret=ret*base; base=base*base; b>>=1;
}return ret;
}
inline LL Cout(LL x,LL y){
LL val(1<<x);
val*=(y?3:1);
return n/val;
}
int main(){
scanf("%d",&n);
LL p(0);
while((1<<p)<=n) ++p;
f[1][--p][0]=1;
if((1<<p-1)*3<=n) f[1][p-1][1]=1;
for(LL i=1;i<n;++i)
for(LL j=0;j<=p;++j){
for(LL k=0;k<=1;++k){
f[i+1][j][k]=(f[i+1][j][k]+1ll*f[i][j][k]*(Cout(j,k)-i))%mod;
if(j) f[i+1][j-1][k]=(f[i+1][j-1][k]+1ll*f[i][j][k]*(Cout(j-1,k)-Cout(j,k)))%mod;
if(k) f[i+1][j][k-1]=(f[i+1][j][k-1]+1ll*f[i][j][k]*(Cout(j,k-1)-Cout(j,k)))%mod;
}
}
printf("%d",f[n][0][0]);
return 0;
}
CF1174E Ehab and the Expected GCD Problem(动规+数论+分解)的更多相关文章
- CF1174E Ehab and the Expected GCD Problem(DP,数论)
题目大意:对于一个序列,定义它的价值是它的所有前缀的 $\gcd$ 中互不相同的数的个数.给定整数 $n$,问在 $1$ 到 $n$ 的排列中,有多少个排列的价值达到最大值.答案对 $10^9+7$ ...
- Codeforces Round #563 (Div. 2) E. Ehab and the Expected GCD Problem
https://codeforces.com/contest/1174/problem/E dp 好题 *(if 满足条件) 满足条件 *1 不满足条件 *0 ///这代码虽然写着方便,但是常数有点大 ...
- codeforces#1157D. Ehab and the Expected XOR Problem(构造)
题目链接: http://codeforces.com/contest/1174/problem/D 题意: 构造一个序列,满足以下条件 他的所有子段的异或值不等于$x$ $1 \le a_i< ...
- 【CF1174D】 Ehab and the Expected XOR Problem - 构造
题面 Given two integers \(n\) and \(x\), construct an array that satisfies the following conditions: · ...
- CF1174D Ehab and the Expected XOR Problem
思路: 使用前缀和技巧进行问题转化:原数组的任意子串的异或值不能等于0或x,可以转化成前缀异或数组的任意两个元素的异或值不能等于0或x. 实现: #include <bits/stdc++.h& ...
- CF1174D Ehab and the Expected XOR Problem(二进制)
做法 求出答案序列的异或前缀和\(sum_i\),\([l,r]\)子段异或和可表示为\(sum_r\bigoplus sum_{l-1}\) 故转换问题为,填\(sum\)数组,数组内的元素不为\( ...
- CF D. Ehab and the Expected XOR Problem 贪心+位运算
题中只有两个条件:任意区间异或值不等于0或m. 如果只考虑区间异或值不等于 0,则任意两个前缀异或值不能相等. 而除了不能相等之外,还需保证不能出现任意两个前缀异或值不等于m. 即 $xor[i]$^ ...
- 题解-Ehab's REAL Number Theory Problem
Ehab's REAL Number Theory Problem 前置知识 质数 分解质因数 无向无权图最小环<讲> Ehab's REAL Number Theory Problem/ ...
- 【算法系列学习】codeforces C. Mike and gcd problem
C. Mike and gcd problem http://www.cnblogs.com/BBBob/p/6746721.html #include<iostream> #includ ...
随机推荐
- easyExcel用于导入导出
1.添加依赖: <!-- 现在已经更新到1.1.2-beta5 --> <dependency> <groupId>com.alibaba</groupId& ...
- 扩展 MongoDB.Driver 支持实体
针对MongoDB的官方C#驱动进行扩展 一.安装 Install-Package Apteryx.MongoDB.Driver.Extend 移步我的项目https://github.com/cod ...
- module 'cv2' has no attribute 'KNearest_create'
python版本:3.6.5 opencv版本:3.2.0 使用的是jupyter notebook 源代码如下: import cv2 import numpy as np import matpl ...
- CSS_引入方式
一 CSS的引入方式 CSS是Cascading Style Sheets的简称,中文称为层叠样式表,用来控制网页数据的表现,可以使网页的表现与数据内容分离 1.行内式 ...
- Oracle数据的导入与导出
本文针对window操作系统与oracle12C的版本. 1.sqlplus执行单个sql文件 1.执行sqlplus登陆命令:sqlplus username/password@host:port/ ...
- Android笔记(十四) Android中的基本组件——按钮
Android中的按钮主要包括Button和ImageButton两种,Button继承自TextView,而ImageButton继承自ImageView.Button生成的按钮上显示文字,而Ima ...
- k8s的网络
K8S的网络中主要存在4种类型的通信: ①同一Pod内的容器间通信 ②各个Pod彼此间的通信 ③Pod和Service间的通信 ④集群外部流量和Service之间的通信 K8S为Pod和Ser ...
- datatable修改每页默认显示的数量
datatable修改每页默认显示的数量 一.总结 一句话总结: iDisplayLength属性:'iDisplayLength':50 1.datatable默认每页显示50个? iDisplay ...
- JDK源码那些事儿之LinkedBlockingQueue
今天继续讲解阻塞队列,涉及到了常用线程池的其中一个队列LinkedBlockingQueue,从类命名部分我们就可以看出其用意,队列中很多方法名是通用的,只是每个队列内部实现不同,毕竟实现的都是同一个 ...
- 根据参数显示类别(三级联动,需要JSON数据)
根据参数显示类别(三级联动,需要JSON数据) Scripts/Category.js 调用方法: $(function () { BindCategory(); //默认绑定文本框中的值 BindC ...