【51Nod 1769】Clarke and math2

题面

51Nod

题解

对于一个数论函数\(f\),\(\sum_{d|n}f(d)=(f\times 1)(n)\)。

其实题目就是要求\(g=f\times 1^k\)。

考虑\(1^k(n)\)怎么求,因为\(1(n)\)是个积性函数,所以\(1^k(n)\)也是个积性函数。

我们考虑对于\(n\)的每个质因子\(p\)和它的次数\(r\),求出对应函数的值。

那么就相当于在每个不同的\(i_{j-1}\)及\(i_j\)中插入一个质因子,表示乘上\(p\)倍,也可以在同一个位置插。

那么根据排列组合,这个问题的答案就是\(k-1+r\choose r\),然后把每个质因数的贡献乘起来就是答案。

代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int Mod = 1e9 + 7;
inline int gi() {
register int data = 0, w = 1;
register char ch = 0;
while (!isdigit(ch) && ch != '-') ch = getchar();
if (ch == '-') w = -1, ch = getchar();
while (isdigit(ch)) data = (10ll * data + ch - '0') % Mod, ch = getchar();
return w == 1 ? data : (-data + Mod) % Mod;
}
int fpow(int x, int y) {
int res = 1;
while (y) {
if (y & 1) res = 1ll * res * x % Mod;
x = 1ll * x * x % Mod;
y >>= 1;
}
return res;
}
const int MAX_N = 5e5 + 5;
int fac[25], ifc[25], C[25];
int N, K, f[MAX_N], g[MAX_N], h[MAX_N], cur[MAX_N]; int main () {
#ifndef ONLINE_JUDGE
freopen("cpp.in", "r", stdin);
#endif
fac[0] = 1; for (int i = 1; i <= 20; i++) fac[i] = 1ll * i * fac[i - 1] % Mod;
ifc[20] = fpow(fac[20], Mod - 2);
for (int i = 19; ~i; i--) ifc[i] = 1ll * ifc[i + 1] * (i + 1) % Mod;
N = gi(), K = gi();
for (int i = 1; i <= N; i++) f[i] = gi(), g[i] = 1, cur[i] = i;
for (int i = 0; i <= 20; i++) {
int nw = (i + K - 1) % Mod; C[i] = ifc[i];
for (int j = 0; j < i; j++) C[i] = 1ll * C[i] * (nw - j + Mod) % Mod;
}
for (int i = 2; i <= N; i++) {
if (cur[i] == 1) continue;
for (int j = i; j <= N; j += i) {
int k = 0;
while (cur[j] % i == 0) ++k, cur[j] /= i;
g[j] = 1ll * g[j] * C[k] % Mod;
}
}
for (int i = 1; i <= N; i++)
for (int j = i; j <= N; j += i)
h[j] = (h[j] + 1ll * f[i] * g[j / i]) % Mod;
for (int i = 1; i <= N; i++) printf("%d ", h[i]);
putchar('\n');
return 0;
}

【51Nod 1769】Clarke and math2的更多相关文章

  1. 【51Nod1769】Clarke and math2(数论,组合数学)

    [51Nod1769]Clarke and math2(数论,组合数学) 题面 51Nod 题解 考虑枚举一个\(i_k\),枚举一个\(i\),怎么计算\(i_k\)对\(i\)的贡献. 把\(\f ...

  2. 【51NOD 1847】奇怪的数学题(莫比乌斯反演,杜教筛,min_25筛,第二类斯特林数)

    [51NOD 1847]奇怪的数学题(莫比乌斯反演,杜教筛,min_25筛,第二类斯特林数) 题面 51NOD \[\sum_{i=1}^n\sum_{j=1}^nsgcd(i,j)^k\] 其中\( ...

  3. 【51Nod 1244】莫比乌斯函数之和

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 模板题... 杜教筛和基于质因子分解的筛法都写了一下模板. 杜教筛 ...

  4. 【51Nod 1501】【算法马拉松 19D】石头剪刀布威力加强版

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1501 dp求出环状不连续的前缀和,剩下东西都可以算出来,比较繁琐. 时间 ...

  5. 【51Nod 1622】【算法马拉松 19C】集合对

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1622 简单题..直接暴力快速幂 #include<cstdio&g ...

  6. 【51Nod 1616】【算法马拉松 19B】最小集合

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1616 这道题主要是查询一个数是不是原有集合的一个子集的所有数的gcd. ...

  7. 【51Nod 1674】【算法马拉松 19A】区间的价值 V2

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1674 对区间分治,统计\([l,r]\)中经过mid的区间的答案. 我的 ...

  8. 【hdu 5628】Clarke and math (Dirichlet卷积)

    hdu 5628 Clarke and math 题意 Given f(i),1≤i≤n, calculate \(\displaystyle g(i) = \sum_{i_1 \mid i} \su ...

  9. 【51nod 1785】数据流中的算法

    Description 51nod近日上线了用户满意度检测工具,使用高级人工智能算法,通过用户访问时间.鼠标轨迹等特征计算用户对于网站的满意程度.   现有的统计工具只能统计某一个窗口中,用户的满意程 ...

随机推荐

  1. erlang 资源

    https://github.com/ninenines https://github.com/drobakowski https://github.com/dizzyd

  2. LeetCode 141:环形链表 Linked List Cycle

    给定一个链表,判断链表中是否有环. 为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始). 如果 pos 是 -1,则在该链表中没有环. Given a l ...

  3. jQuery 源码分析(五) map函数 $.map和$.fn.map函数 详解

    $.map() 函数用于使用指定函数处理数组中的每个元素(或对象的每个属性),并将处理结果封装为新的数组返回,该函数有三个参数,如下: elems Array/Object类型 指定的需要处理的数组或 ...

  4. Docker学习(六)-Kubernetes - Spring Boot 应用

    接上一篇 https://www.cnblogs.com/woxpp/p/11872155.html 新建 k8s-demo.yaml apiVersion: apps/v1beta2 kind: D ...

  5. sql语句规范参考

    公司有SQL语句规范的参考,这里特别做个笔记. 书写风格 1. 语句关键字应全部使用小写. 2. 引用字符时应使用单引号.如:update testable set idcol=’abcd’. 3. ...

  6. 配置 ASP.NET Core 请求(Request)处理管道

    配置 ASP.NET Core 请求(Request)处理管道 在本节中,我们将讨论使用中间件组件为 asp.net core 应用程序配置请求处理管道. 作为应用程序启动的一部分,我们要在Confi ...

  7. charles注册码及中文版本,支持window和mac

    安装证书: 安装完证书之后设置代理 2个* ,代表全部 注册码: Registered Name: https://zhile.io License Key: 48891cf209c6d32bf4 破 ...

  8. navicat 连接 mysql 出现Client does not support authentication protocol requested by server解决方案

    安装了navicat 和 mysql,结果最后在navicat中连接mysql时,出现了如下错误提示: Client does not support authentication protocol ...

  9. JZOJ.2117. 【2016-12-30普及组模拟】台风

    题目大意: 天气预报频道每天从卫星上接受卫星云图.图片被看作是一个矩阵,每个位置上要么是”#”,要么”.”,”#”表示该位置没有云,”.”表示有云,地图上每个位置有多达8个相邻位置,分别是,左上.上. ...

  10. C#中全局作用域的常量、字段、属性、方法的定义与使用

    场景 在开发中,经常会有一些全局作用域的常量.字段.属性.方法等. 需要将这些设置为全局作用域保存且其实例唯一. 注: 博客主页: https://blog.csdn.net/badao_liuman ...