当前位置:网站首页>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;
}
}
边栏推荐
- JS select all and tab bar switching, simple comments
- 解决方案:智慧工地智能巡檢方案視頻監控系統
- Epoll and IO multiplexing of redis
- 24. Query table data (basic)
- CAD ARX 获取当前的视口设置
- Common functions for PHP to process strings
- 数据治理:误区梳理篇
- 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
- Vit (vision transformer) principle and code elaboration
- Analysis of Top1 accuracy and top5 accuracy examples
猜你喜欢
数据治理:主数据的3特征、4超越和3二八原则
Generator Foundation
Make learning pointer easier (3)
. Net 6 learning notes: what is NET Core
22. Empty the table
Convolution, pooling, activation function, initialization, normalization, regularization, learning rate - Summary of deep learning foundation
将 NFT 设置为 ENS 个人资料头像的分步指南
NFT smart contract release, blind box, public offering technology practice -- contract
指针和数组笔试题解析
[Yugong series] February 2022 U3D full stack class 011 unity section 1 mind map
随机推荐
Le chemin du navigateur Edge obtient
[cf gym101196-i] waif until dark network maximum flow
Circuit breaker: use of hystrix
[KMP] template
Pangolin Library: control panel, control components, shortcut key settings
Transformer principle and code elaboration
PHP - Common magic method (nanny level teaching)
Asia Pacific Financial Media | female pattern ladyvision: forced the hotel to upgrade security. The drunk woman died in the guest room, and the hotel was sentenced not to pay compensation | APEC secur
On why we should program for all
861. Score after flipping the matrix
Solution: intelligent site intelligent inspection scheme video monitoring system
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
(lightoj - 1410) consistent verbs (thinking)
[count] [combined number] value series
49. Sound card driven article collection
2.10transfrom attribute
Esrally domestic installation and use pit avoidance Guide - the latest in the whole network
你想知道的ArrayList知识都在这
解决方案:智慧工地智能巡檢方案視頻監控系統
Wireshark grabs packets to understand its word TCP segment