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 ...
随机推荐
- Sitecore详细安装(包含sitecore安装过程截图)
一.到Sitecore 官网下载安装包 1)浏览器中输入https://dev.sitecore.net/Downloads/Sitecore_Experience_Platform.aspx 2)安 ...
- HashSet, HashTable
HashTable 存储键值对 , Hashtable和Dictionary<TKey,TValue>都是存键值对 HashSet 只存储值,盛放不同的数据,相同的数据只保留一份 Hash ...
- python XML文件解析:用ElementTree解析XML
Python标准库中,提供了ET的两种实现.一个是纯Python实现的xml.etree.ElementTree,另一个是速度更快的C语言实现xml.etree.cElementTree.请记住始终使 ...
- python 使用json.dumps() 的indent 参数,获得漂亮的格式化字符串后输出
想获得漂亮的格式化字符串后输出,可以使用json.dumps() 的indent 参数.它会使得输出和pprint() 函数效果类似 >>> data {'age': 4, 'nam ...
- 任务调度工具 Apache Airflow 初识
参考文章: Apache Airflow (incubating) Documentation — Airflow ... 任务调度神器 airflow 之初体验 airflow 介绍 - 简书(原文 ...
- linux常用命令:cd 命令
Linux cd 命令可以说是Linux中最基本的命令语句,其他的命令语句要进行操作,都是建立在使用 cd 命令上的.所以,学习Linux 常用命令,首先就要学好 cd 命令的使用方法技巧. 1. 命 ...
- 转:wcf大文件传输解决之道(1)
首先声明,文章思路源于MSDN中徐长龙老师的课程整理,加上自己的一些心得体会,先总结如下: 在应对与大文件传输的情况下,因为wcf默认采用的是缓存加载对象,也就是说将文件包一次性接受至缓存中,然后生成 ...
- websocket 群聊单聊
websocket 介绍 介绍引自 https://segmentfault.com/a/1190000012709475 群聊 from flask import Flask, request, r ...
- [转载]ViewPort <meta>标记
ViewPort <meta>标记用于指定用户是否可以缩放Web页面,如果可以,那么缩放到的最大和最小缩放比例是什么.使用 ViewPort <meta>标记还表示文档针对移动 ...
- vue 加载更多
<template> <div> <ul> <li v-for="item in articles"> ...