当前位置:网站首页>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
边栏推荐
- 24、两两交换链表中的节点(链表)
- 【leetcode】102. Sequence traversal of binary tree
- shell脚本免交互
- 利用多线程按顺序连续输出abc10次
- IDEA——》每次启动都会Indexing或 scanning files to index
- Realize data value through streaming data integration (1)
- 微信小程序简介、发展史、小程序的优点、申请账号、开发工具、初识wxml文件和wxss文件
- Realizing data value through streaming data integration (4) - streaming data pipeline
- Swagger2 自定义参数注解如何不显示
- Juc并发编程09——Condition实现源码分析
猜你喜欢
![Jerry's more accurate determination of abnormal address [chapter]](/img/ed/a08949bfc63823baf25fd57c324996.png)
Jerry's more accurate determination of abnormal address [chapter]

精彩回顾 | DEEPNOVA x Iceberg Meetup Online《基于Iceberg打造实时数据湖》

Example of pop-up task progress bar function based on pyqt5

Redis design and Implementation

IDEA——》每次启动都会Indexing或 scanning files to index

lnmp的配置

JUC concurrent programming 09 -- source code analysis of condition implementation

Charles 功能介绍和使用教程

Read LSTM (long short term memory)

SQL Server 游标循环表数据
随机推荐
206、反转链表(链表)
第120章 SQL函数 ROUND
Understand the new economic model of platofarm and its ecological progress
LeetCode 1249. Minimum remove to make valid parents - FB high frequency question 1
What if Jerry's function to locate the corresponding address is not accurate sometimes? [chapter]
任意文件读取漏洞 利用指南
转:毛姆:阅读是一座随身携带的避难所
209、长度最小的子数组(数组)
349、两个数组的交集
SQLServer 查询数据库死锁
Jinglianwen technology - professional data annotation company and intelligent data annotation platform
DBA common SQL statements (2) - SGA and PGA
Sim Api User Guide(8)
JVM——》常用参数
Reading integrity monitoring techniques for vision navigation systems - 3 background
MySql常用语句
Comparison and practice of prototype design of knowledge service app
Arm debugging (1): two methods to redirect printf to serial port in keil
IDEA——》每次启动都会Indexing或 scanning files to index
Leetcode22:括号生成