当前位置:网站首页>Dirichlet prefix sum (number theory optimization formula sub complexity weapon)
Dirichlet prefix sum (number theory optimization formula sub complexity weapon)
2022-04-23 10:33:00 【Zimba_】
summary
When the formula is optimized to ∑ d = 1 n ∑ d ∣ i s ( i ) \sum_{d=1}^{n}\sum_{d|i}s(i) ∑d=1n∑d∣is(i) In a similar form , We can o ( n l o g n ) o(nlogn) o(nlogn) do . But when n n n take 1 0 7 10^7 107 It's very dangerous when , Until today, I found such a thing ——Dirichlet The prefix and . It can be o ( n l o g l o g n ) o(nloglogn) o(nloglogn) Solve this problem within the complexity of , Fast approximation o ( n ) o(n) o(n) 了 .
This blog is used to write down the board , To learn, you can see This blog .
Dirichlet The prefix and
Formula :( Given a a a, seek b b b)
b [ d ] = ∑ i ∣ d a [ i ] b[d]=\sum_{i|d}a[i] b[d]=i∣d∑a[i]
Code :
for(int i=0;i<tot&&prime[i]<=n;i++)
{
for(int j=1;j*prime[i]<=n;j++)
{
a[j*prime[i]]+=a[j];
}
}
Dirichlet Suffixes and
Formula :( Given a a a, seek b b b)
b [ d ] = ∑ d ∣ i a [ i ] b[d]=\sum_{d|i}a[i] b[d]=d∣i∑a[i]
Code :
for(int i=0;i<tot&&prime[i]<=n;i++)
{
for(int j=n/prime[i];j;j--)
{
a[j]+=a[j*prime[i]];
}
}
Push backward Dirichlet The prefix and
Formula :( Given b b b, seek a a a)
b [ d ] = ∑ i ∣ d a [ i ] b[d]=\sum_{i|d}a[i] b[d]=i∣d∑a[i]
Code :
for(int i=tot-1;i>=0;i--)
{
for(int j=n/prime[i];j;j--)
{
a[j*prime[i]]-=a[j];
}
}
Push backward Dirichlet Suffixes and
Formula :( Given b b b, seek a a a)
b [ d ] = ∑ d ∣ i a [ i ] b[d]=\sum_{d|i}a[i] b[d]=d∣i∑a[i]
Code :
for(int i=tot-1;i>=0;i--)
{
for(int j=1;j*prime[i]<=n;++j)
{
a[j]-=a[j*prime[i]];
}
}
appendix ( Matching prime sieve )
Code :
int notPrime[MAXN],prime[MAXN],tot;
void getPrime(int n)
{
notPrime[1]=1;
for(int i=2;i<=n;i++)
{
if(!notPrime[i])prime[tot++]=i;
for(int j=0;j<tot&&i*prime[j]<=n;j++)
{
notPrime[i*prime[j]]=1;
if(i%prime[j]==0)break;
}
}
}
版权声明
本文为[Zimba_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230621424645.html
边栏推荐
- Construction and traversal of binary tree
- MapReduce compression
- 得到知识服务app原型设计比较与实践
- Sim Api User Guide(4)
- Configuration of LNMP
- Redis design and Implementation
- Six practices of Windows operating system security attack and defense
- SQL Server 游标循环表数据
- What are Jerry's usual program exceptions? [chapter]
- Chapter 3 enable and adjust the size of IM column storage (im-3.1)
猜你喜欢

Initial exploration of NVIDIA's latest 3D reconstruction technology instant NGP

0704、ansible----01

101. Symmetric Tree

Solve the problem of installing VMware after uninstalling

Question bank and answers of Shanghai safety officer C certificate examination in 2022

shell脚本免交互
Detailed explanation of MapReduce calculation process
![[provincial election joint examination 2022 d2t1] card (state compression DP, FWT convolution)](/img/e4/3c47edbc3241ba86f10a1ac8a963fd.png)
[provincial election joint examination 2022 d2t1] card (state compression DP, FWT convolution)

Charles function introduction and use tutorial

【省选联考 2022 D2T1】卡牌(状态压缩 DP,FWT卷积)
随机推荐
SQL server query database deadlock
SSH利用私钥无密钥连接服务器踩坑实录
Art template template engine
Read LSTM (long short term memory)
24、两两交换链表中的节点(链表)
SQL Server cursor circular table data
454. Sum of four numbers (hash table)
Reading integrity monitoring techniques for vision navigation systems - 3 background
MySQL how to merge the same data in the same table
微信小程序简介、发展史、小程序的优点、申请账号、开发工具、初识wxml文件和wxss文件
Linked list intersection (linked list)
利用多线程按顺序连续输出abc10次
转:毛姆:阅读是一座随身携带的避难所
349. Intersection of two arrays
59、螺旋矩阵(数组)
Sim Api User Guide(7)
203、移出链表元素(链表)
ansible 云计算 自动化
Jerry sometimes finds that the memory has been tampered with, but there is no exception. How should he find it? [chapter]
任意文件读取漏洞 利用指南