Codeforces 1139D Steps to One dp
啊, 我要死了, 这种垃圾题居然没写出来, 最后十分钟才发现错在哪。
不知道为什么我以为 对于一个数x , 除了它的因子和它的倍数都是和它互质的, 我脑子是抽了吗?
随便瞎dpdp的题。。 还熬夜打cf好暴躁啊啊啊。
我求我自己以后打比赛多动动脑子。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ;
const double eps = 1e-;
const double PI = acos(-); int Power(int a, int b) {
int ans = ;
while(b) {
if(b & ) ans = 1ll * ans * a % mod;
a = 1ll * a * a % mod; b >>= ;
}
return ans;
}
void add(int &a, int b) {
a += b; if(a >= mod) a -= mod;
} int n, ans, dp[N];
int inv[N]; vector<int> fac[N];
vector<int> cnt[N]; int dfs(int x) {
if(x == ) return ;
if(~dp[x]) return dp[x];
dp[x] = ;
int ret = n / x;
int res = SZ(fac[x]);
add(dp[x], (1ll * inv[n - ret] * n + mod) % mod);
for(int i = ; i < SZ(fac[x]) - ; i++) {
add(dp[x], 1ll * inv[n - ret] * cnt[x][i] % mod * dfs(fac[x][i]) % mod);
}
return dp[x];
} int main() {
memset(dp, -, sizeof(dp));
inv[] = ;
for(int i = ; i < N; i++) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
for(int i = ; i < N; i++)
for(int j = i; j < N; j += i)
fac[j].push_back(i);
scanf("%d", &n);
for(int i = ; i <= n; i++) {
cnt[i].resize(SZ(fac[i]));
for(int j = SZ(fac[i]) - ; j >= ; j--) {
cnt[i][j] = n / fac[i][j];
for(int k = j + ; k < SZ(fac[i]); k++)
if(fac[i][k] % fac[i][j] == )
cnt[i][j] -= cnt[i][k];
}
}
for(int i = ; i <= n; i++)
add(ans, 1ll * inv[n] * dfs(i) % mod);
printf("%d\n", ans);
return ;
} /*
*/
Codeforces 1139D Steps to One dp的更多相关文章
- Codeforces.1139D.Steps to One(DP 莫比乌斯反演)
题目链接 啊啊啊我在干什么啊.怎么这么颓一道题做这么久.. 又记错莫比乌斯反演式子了(╯‵□′)╯︵┻━┻ \(Description\) 给定\(n\).有一个初始为空的集合\(S\).令\(g\) ...
- codeforces#1139D. Steps to One (概率dp+莫比乌斯反演)
题目链接: http://codeforces.com/contest/1139/problem/D 题意: 在$1$到$m$中选择一个数,加入到一个初始为空的序列中,当序列的$gcd$和为$1$时, ...
- Codeforces - 1139D - Steps to One (概率DP+莫比乌斯反演)
蒟蒻数学渣呀,根本不会做. 解法是参考 https://blog.csdn.net/xs18952904/article/details/88785210 这位大佬的. 状态的设计和转移如上面博客一样 ...
- [Codeforces 1139D] Steps to One
[题目链接] https://codeforces.com/contest/1139/problem/D [算法] 考虑dp 设fi表示现在gcd为i , 期望多少次gcd变为1 显然 , fi = ...
- Codeforces 1139D(推式子+dp)
题目传送 推公式博客传送 推完式子就是去朴素地求就行了Orz const int maxn = 1e5 + 5; const int mod = 1e9 + 7; int m, mu[maxn], v ...
- [BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆)
[BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆) 题面 一棵二叉树的所有点的点权都是给定的集合中的一个数. 让你求出1到m中所有权 ...
- Codeforces Round #321 (Div. 2) A. Kefa and First Steps【暴力/dp/最长不递减子序列】
A. Kefa and First Steps time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces 1139D(期望dp)
题意是模拟一个循环,一开始有一个空序列,之后每次循环: 1.从1到m中随机选出一个数字添加进去,每个数字被选的概率相同. 2.检查这个序列的gcd是否为1,如果为1则停止,若否则重复1操作直至gcd为 ...
- codeforces 721C (拓排 + DP)
题目链接:http://codeforces.com/contest/721/problem/C 题意:从1走到n,问在时间T内最多经过多少个点,按路径顺序输出. 思路:比赛的时候只想到拓排然后就不知 ...
随机推荐
- pipeline
执行顺序:pipeline 写 pipeline类class Scrapyproject1Pipeline(object): def process_item(self, item, spider): ...
- 自定义admin(self_admin)
admin.site.register(models.UserInfo)admin.site.register(models.Book,Book_admin)######当下面注册的这个表里面没有这个 ...
- Jquery分享插件
效果图如下: 代码如下: <!DOCTYPE HTML> <html style="padding-bottom: 54px;"> <head> ...
- Confluence 6 Windows 中以服务方式自动重启修改运行服务的用户
基于安全的考虑,如果你希望你的 Confluence 不是在系统中以管理员的身份运行或者你使用网络驱动器来存储备份,附件和索引的话,你可以以其他用户来运行 Confluence. 希望修改用户,打开 ...
- Confluence 6 外部参考
一个外部参考的意思是任何站点链接到你 Confluence 的实例.任何时候当 Confluence 的用户单击这个外部链接的时候,Confluence 可以记录这次单击为参考. 在默认的情况下,外部 ...
- js工具库---Lodash
Lodash是一个一致性.模块化.高性能的 JavaScript 实用工具库 为什么选择 Lodash ? Lodash 通过降低 array.number.objects.string 等等的使用难 ...
- ipone mac真机调试
safiri 识别不了iPhone 真机 需要在iPhone上 做设置 safri-> 高级 ->web检查器 进行设置,然后重新启动 safri即可...
- hdu1213并查集
板子题不多说,上代码 #include<iostream> #include<cstdio> #include<cstring> using namespace s ...
- centos--git搭建之Gogs安装
1.下载git yum intall -y git 2. 创建git用户(必须新创建git用户, 用root用户会导致无法下载) #创建git用户 sudo adduser git #给git用户设置 ...
- AI学习吧-支付宝支付
支付宝支付流程 1.接收前端发过来的贝里数和结算金额 2.检查贝里数是否够用 3.获取结算中心的课程并应用优惠券 4.应用未绑定课程的优惠券 5.判断总价格减去优惠券价格是否等于实际支付金额 6.生成 ...