Steps to One

啊, 我要死了, 这种垃圾题居然没写出来, 最后十分钟才发现错在哪。

不知道为什么我以为 对于一个数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的更多相关文章

  1. Codeforces.1139D.Steps to One(DP 莫比乌斯反演)

    题目链接 啊啊啊我在干什么啊.怎么这么颓一道题做这么久.. 又记错莫比乌斯反演式子了(╯‵□′)╯︵┻━┻ \(Description\) 给定\(n\).有一个初始为空的集合\(S\).令\(g\) ...

  2. codeforces#1139D. Steps to One (概率dp+莫比乌斯反演)

    题目链接: http://codeforces.com/contest/1139/problem/D 题意: 在$1$到$m$中选择一个数,加入到一个初始为空的序列中,当序列的$gcd$和为$1$时, ...

  3. Codeforces - 1139D - Steps to One (概率DP+莫比乌斯反演)

    蒟蒻数学渣呀,根本不会做. 解法是参考 https://blog.csdn.net/xs18952904/article/details/88785210 这位大佬的. 状态的设计和转移如上面博客一样 ...

  4. [Codeforces 1139D] Steps to One

    [题目链接] https://codeforces.com/contest/1139/problem/D [算法] 考虑dp 设fi表示现在gcd为i , 期望多少次gcd变为1 显然 , fi = ...

  5. Codeforces 1139D(推式子+dp)

    题目传送 推公式博客传送 推完式子就是去朴素地求就行了Orz const int maxn = 1e5 + 5; const int mod = 1e9 + 7; int m, mu[maxn], v ...

  6. [BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆)

    [BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆) 题面 一棵二叉树的所有点的点权都是给定的集合中的一个数. 让你求出1到m中所有权 ...

  7. 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 ...

  8. Codeforces 1139D(期望dp)

    题意是模拟一个循环,一开始有一个空序列,之后每次循环: 1.从1到m中随机选出一个数字添加进去,每个数字被选的概率相同. 2.检查这个序列的gcd是否为1,如果为1则停止,若否则重复1操作直至gcd为 ...

  9. codeforces 721C (拓排 + DP)

    题目链接:http://codeforces.com/contest/721/problem/C 题意:从1走到n,问在时间T内最多经过多少个点,按路径顺序输出. 思路:比赛的时候只想到拓排然后就不知 ...

随机推荐

  1. css效果文字多了就...

    开发中经常会遇见这样的问题,一段文字或者一段标题过长了,就让超出长度的部分益...替换.具体怎么做的呢?直接上代码: <style> *{ margin: 0; padding: 0; } ...

  2. ansible笔记(7):常用模块之系统类模块

    ansible笔记():常用模块之系统类模块 cron模块 cron模块可以帮助我们管理远程主机中的计划任务,功能相当于crontab命令. 在了解cron模块的参数之前,先写出一些计划任务的示例,示 ...

  3. hibernate映射关系(多对多)

    Student与Teacher关系多对多(只建了2个实体类) public class Student { private int id; private String name; private S ...

  4. Solidworks设计电路外形导入AltiumDesigner

    将实际设计好的三维电路图的底板(单个零件模式下)轮廓另存为dwf或者dwg 这时候会出现一个选项框,需要进行一些设置 单位选择mm,这个按照自己的需求选择单位 单位映射选择为1mm,也就是1:1的比例 ...

  5. JS ----实现复制粘贴功能 (剪切板应用clipboardData)

    注意:ie7,与ie8 对网页有个复制的权限,需在“安全”中的“自定义级别”的脚本中设置 clipboardData 对象 提供了对剪贴板的访问. 三个方法 :1.clearData(sDataFor ...

  6. Shiro配置URL过滤

      常用过滤器: anon     不需要认证 authc     需要认证 user     验证通过或RememberMe登录的都可以   URL说明: /admin?=authc      表示 ...

  7. [PHP]php缓冲 output_buffering的使用详解

    bufferbuffer是一个内存地址空间,Linux系统默认大小一般为4096(4kb),即一个内存页.主要用于存储速度不同步的设备或者优先级不同的设备之间传办理数据的区域.通过buffer,可以使 ...

  8. c#获取鼠标坐标

    用Control.MousePosition获得当前鼠标的坐标CurrentPoint,使用Control.PointToClient方法,前面获得的CurrentPoint作为其参数,返回的Poin ...

  9. swift 实践- 12 -- UIPickerView

    import UIKit class ViewController: UIViewController , UIPickerViewDelegate,UIPickerViewDataSource{ v ...

  10. socket-WebSocket HttpListener TcpListener 服务端客户端的具体使用案例

    /// <summary>/// 启动服务监听的ip和端口的主线程/// </summary>/// <param name="tunnelPort" ...