当前位置:网站首页>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;
}
}边栏推荐
- Pangolin Library: control panel, control components, shortcut key settings
- 继电反馈PID控制器参数自整定
- Opencv learning notes 9 -- background modeling + optical flow estimation
- 解决方案:智慧工地智能巡检方案视频监控系统
- Hill sort c language
- 将 NFT 设置为 ENS 个人资料头像的分步指南
- Common functions for PHP to process strings
- 1204 character deletion operation (2)
- Notes on software development
- onie支持pice硬盘
猜你喜欢

Parameter self-tuning of relay feedback PID controller
![[Yugong series] February 2022 U3D full stack class 011 unity section 1 mind map](/img/c3/1b6013bfb2441219bf621c3f0726ea.jpg)
[Yugong series] February 2022 U3D full stack class 011 unity section 1 mind map

Easy to use tcp-udp_ Debug tool download and use

MEX有关的学习

matplotlib. Widgets are easy to use
![[redis] Introduction to NoSQL database and redis](/img/95/229d7a08e94245f2733b8c59201cff.png)
[redis] Introduction to NoSQL database and redis

Golang DNS write casually

链表面试题(图文详解)

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

Go learning notes (3) basic types and statements (2)
随机推荐
Database addition, deletion, modification and query
Hill sort c language
图像融合--挑战、机遇与对策
datax自检报错 /datax/plugin/reader/._drdsreader/plugin.json]不存在
[nonlinear control theory]9_ A series of lectures on nonlinear control theory
hcip--mpls
CAD ARX gets the current viewport settings
Iterator Foundation
[count] [combined number] value series
Solution: système de surveillance vidéo intelligent de patrouille sur le chantier
DataX self check error /datax/plugin/reader/_ drdsreader/plugin. Json] does not exist
使用 BR 备份 TiDB 集群数据到兼容 S3 的存储
Linked list interview questions (Graphic explanation)
P3047 [USACO12FEB]Nearby Cows G(树形dp)
How to estimate the number of threads
HTTP cache, forced cache, negotiated cache
octomap averageNodeColor函数说明
flask返回文件下载
Analysis of Top1 accuracy and top5 accuracy examples
MySQL view tablespace and create table statements