当前位置:网站首页>Introduction to number theory (greatest common divisor, prime sieve, inverse element)
Introduction to number theory (greatest common divisor, prime sieve, inverse element)
2022-07-06 08:00:00 【D αī s ч】
One 、 greatest common divisor (gcd)
ll gcd(ll x, ll y)
{
return y ? gcd(y, x % y) : x;
}gcd(a,b,c)=gcd(a,b-a,c-b) Most of them can be promoted
Two 、 Prime sieve ( Euler screen , For Euler function )
int least[maxn], prime[maxn], phi[maxn], tot;
void euler(int n)
{
int i, j;
for (i = 2; i <= n; i++)
{
if (!least[i])
{
least[i] = i;
prime[++tot] = i;
phi[i] = i - 1;
}
for (j = 1; j <= tot && i * prime[j] <= n; j++)
{
least[i * prime[j]] = prime[j];
if (i % prime[j] == 0)
{
phi[i * prime[j]] = phi[i] * prime[j];
break;
}
else
{
phi[i * prime[j]] = phi[i] * (prime[j] - 1);
}
}
}
}3、 ... and 、 Fast power inverse ( Used for finding large combinatorial numbers )
// Calculate large numbers (a/b)mod c
ll quick_pow(ll a, ll b)
{
ll ans = 1;
while (b)
{
if (b & 1)
ans = (ans * a) % mod;
b >>= 1;
a = (a * a) % mod;
}
return ans;
}
ll inv(ll a, ll b)
{
return (a * quick_pow(b, mod - 2)) % mod;
}ll fa[maxn], fb[maxn];
ll power(ll a, ll b)
{
ll ans = 1;
while (b)
{
if (b & 1)
ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
ll C(ll n, ll k)
{
if (k<0 || k>n)
return 0;
return fa[n] * fb[k] % mod * fb[n - k] % mod;
}
void init()
{
int i;
fa[0] = 1;
fb[0] = 1;
for (i = 1; i < maxn; i++)
{
fa[i] = fa[i - 1] * i % mod;
fb[i] = power(fa[i], mod - 2) % mod;
}
}边栏推荐
- hcip--mpls
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- [Yugong series] creation of 009 unity object of U3D full stack class in February 2022
- [KMP] template
- edge瀏覽器 路徑獲得
- In the era of digital economy, how to ensure security?
- Circuit breaker: use of hystrix
- Binary tree creation & traversal
- 数据治理:误区梳理篇
- datax自检报错 /datax/plugin/reader/._drdsreader/plugin.json]不存在
猜你喜欢

【T31ZL智能视频应用处理器资料】

Opencv learning notes 9 -- background modeling + optical flow estimation

Nft智能合约发行,盲盒,公开发售技术实战--拼图篇

Interview Reply of Zhuhai Jinshan

指针和数组笔试题解析

21. Delete data

opencv学习笔记九--背景建模+光流估计

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

Inspiration from the recruitment of bioinformatics analysts in the Department of laboratory medicine, Zhujiang Hospital, Southern Medical University

Esrally domestic installation and use pit avoidance Guide - the latest in the whole network
随机推荐
Transformer principle and code elaboration
From monomer structure to microservice architecture, introduction to microservices
NFT smart contract release, blind box, public offering technology practice -- jigsaw puzzle
Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center
Sanzi chess (C language)
【T31ZL智能视频应用处理器资料】
49. Sound card driven article collection
Asia Pacific Financial Media | art cube of "designer universe": Guangzhou community designers achieve "great improvement" in urban quality | observation of stable strategy industry fund
指针和数组笔试题解析
Hill sort c language
Database basic commands
The State Economic Information Center "APEC industry +" Western Silicon Valley will invest 2trillion yuan in Chengdu Chongqing economic circle, which will surpass the observation of Shanghai | stable
Opencv learning notes 9 -- background modeling + optical flow estimation
[非线性控制理论]9_非线性控制理论串讲
MFC 给列表控件发送左键单击、双击、以及右键单击消息
Understanding of law of large numbers and central limit theorem
(lightoj - 1410) consistent verbs (thinking)
Learn Arduino with examples
1204 character deletion operation (2)
HTTP cache, forced cache, negotiated cache