hdu5628 Clarke and math
题目地址
题意
求
\]
题解
考虑当\(k=1\)时怎么做
\]
显然可以\(O(\sqrt{n})\)
我们尝试着把它表示成狄利克雷卷积的形式
\]
考虑当\(k=2\)时是什么样子的
\]
表示成狄利克雷卷积形式即为
\]
同理可得当k为任意值时
\]
那么只需要快速幂一下就好,复杂度是\(O(nlognlogk)\)
注意不能枚举单个数的约数,时间复杂度会爆炸,我们可以枚举约数,并计算它对1~n中的数的贡献,这样复杂度是\(O(nlogn)\)的,所以总的复杂度是\(O(nlognlogk)\)
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
int n, k;
int tmp[N], I[N], g[N];
void mul(int *a, int *b) {
for(int i = 1; i <= n; ++i) tmp[i] = 0;
for(int i = 1; i <= n; ++i) {
for(int j = 1; i * j <= n; ++j) {
tmp[i * j] = 1ll * (tmp[i * j] + 1ll * a[i] * b[j]) % mod;
}
}
for(int i = 1; i <= n; ++i) a[i] = tmp[i];
}
int main() {
int T; scanf("%d", &T);
while(T--) {
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; ++i) scanf("%d", &g[i]), I[i] = 1;
while(k) { if(k & 1) mul(g, I); mul(I, I); k >>= 1; }
for(int i = 1; i < n; ++i) printf("%d ", g[i]); printf("%d\n", g[n]);
}
}
hdu5628 Clarke and math的更多相关文章
- 【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 ...
- HDU 5628 Clarke and math——卷积,dp,组合
HDU 5628 Clarke and math 本文属于一个总结了一堆做法的玩意...... 题目 简单的一个式子:给定$n,k,f(i)$,求 然后数据范围不重要,重要的是如何优化这个做法. 这个 ...
- HDU 5628 Clarke and math dp+数学
Clarke and math 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5628 Description Clarke is a patient ...
- HDU 5628 Clarke and math Dirichlet卷积+快速幂
题意:bc round 72 中文题面 分析(官方题解): 如果学过Dirichlet卷积的话知道这玩意就是g(n)=(f*1^k)(n), 由于有结合律,所以我们快速幂一下1^k就行了. 当然,强行 ...
- HDU.5628.Clarke and math(狄利克雷卷积 快速幂)
\(Description\) \[g(i)=\sum_{i_1|i}\sum_{i_2|i_1}\sum_{i_3|i_2}\cdots\sum_{i_k|i_{k-1}}f(i_k)\ mod\ ...
- HDU - 5628:Clarke and math (组合数&线性筛||迪利克雷卷积)
题意:略. 思路:网上是用卷积或者做的,不太会. 因为上一题莫比乌斯有个类似的部分,所以想到了每个素因子单独考虑. 我们用C(x^p)表示p次减少分布在K次减少里的方案数,由隔板法可知,C(x^p)= ...
- 51nod1769 Clarke and math 2
题目 实际上就是要求\(f*I^k\). 因为\(I^k\)是一个积性函数,所以我们只需要考虑如何求\(I^k(p^a)\). 把这个东西转化成一个长度为\(k\)的序列,每一位是\(\frac{i_ ...
- BestCoder Round #72
由于第一次打,只能在div2打.(这么好的机会还没AK真是丢人) T1 Clarke and chemistry 枚举题不解释(我不会告诉你我上来WA了四发的) T2 Clarke and point ...
- hdu 5563 Clarke and five-pointed star 水题
Clarke and five-pointed star Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/show ...
随机推荐
- 擠出機步進馬達的 Steps per Unit 該如何計算?
擠出機步進馬達的 Steps per Unit 該如何計算? 這邊 Steps per Unit 指的是塑料往前推進1mm,步進馬達須要走幾步.依此定義,可知計算方式可以用 步進馬達轉一圈需要的步 ...
- 为什么C++函数形参默认值从最末一个赋值?
[1]函数调用时形参的压栈顺序 1.示例代码如下(VS2010): #include <iostream> using namespace std; ); void fun(int a, ...
- GO slim
1. GO slim简介 GO slims are cut-down versions of the GO ontologies containing a subset of the terms in ...
- vs实现数据库数据迁移
public ActionResult About() { List<ChangeData.Models.old.adsinfo> adsinfo_new = new List<Mo ...
- System.getSecurityManager()
https://www.cnblogs.com/yiwangzhibujian/p/6207212.html java安全管理器SecurityManager入门 一.文章的目的 这是一篇对Jav ...
- django项目----函数和方法的区别
一.函数和方法的区别 1.函数要手动传self,方法不用传 2.如果是一个函数,用类名去调用,如果是一个方法,用对象去调用 举例说明: class Foo(object): def __init__( ...
- JavaUtil 处理Base64的图片上传
UploadImageBase64.java package com.lee.util; import java.io.File; import java.io.FileOutputStream; i ...
- Python进阶【第十一篇】模块(下)之常用模块
内置模块是Python自带的功能,在使用内置模块相应的功能时,需要[先导入]再[使用] 一.time模块 在Python中,通常有这几种方式来表示时间: 时间戳(timestamp):通常来说,时间戳 ...
- OCR技术初识
一.什么是OCR OCR英文全称是Optical Character Recognition,中文叫做光学字符识别.它是利用光学技术和计算机技术把印在或写在纸上的文字读取出来,并转换成一种计算机能够接 ...
- nginx负载均衡六种策略
Nginx服务器之负载均衡策略(6种) 一.关于Nginx的负载均衡 在服务器集群中,Nginx起到一个代理服务器的角色(即反向代理),为了避免单独一个服务器压力过大,将来自用户的请求转发给不同的 ...