当前位置:网站首页>Mathematical knowledge (Euler function)
Mathematical knowledge (Euler function)
2022-07-02 04:52:00 【Wu Yu 4】
Premise : Euler function Φ(n) Express 1~n China and n The number of Coprime numbers .
【 If there are only two numbers 1 A common qualitative factor , Called coprime 】
eg:ϕ(6)=2.[1,2,3,4,5,6]
How to ask for 1~n China and n The number of Coprime numbers ?
From the basic theorem of arithmetic , Any number n It can be expressed by the following formula , among Pi It's the prime factor ,ai Is the index .
Here we will also introduce the principle of inclusion and exclusion :
Since we need to calculate the number of Coprime numbers , Then delete all multiples of prime factors , The operation is as follows :
1) from 1~n Subtract from p1,p2,…,pk Multiple 【- p. 】
2) Add all the pi*pj Multiple 【+ accidentally 】
3) Subtract all pi*pj*pk Multiple 【- p. 】
So :
Simplify to :
Explanation of supplementary steps :
1
2
3
4
5
6
7
First step :
Delete Pi Multiple
-1
-1
-1
-1
Delete Pj Multiple
-1
-1
-1
-1
Delete pk Multiple
-1
-1
-1
-1
The second step :
add pi*pj Multiple
+1
+1
add pi*pk Multiple
+1
+1
add pj*pk Multiple
+1
+1
The third step :
subtract pi*pj*pk Multiple
-1
in total
-1
-1
-1
-1
-1
-1
-1
Topic link :873. Euler function - AcWing Question bank
Topic :
The following code to solve the prime factor can refer to this blog :
Code :
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll t,n;
int main()
{
cin>>t;
while(t--)
{
cin>>n;
ll ans=n;
for(int i=2;i<=n/i;i++)
{
if(n%i==0)
{
ans=ans/i*(i-1);// Equivalent to ans*(1-1/i)
while(n%i==0) n/=i;
}
}
if(n>1) ans=ans/n*(n-1);
cout<<ans<<endl;
}
return 0;
}
边栏推荐
- [graduation season · advanced technology Er] young people have dreams, why are they afraid of hesitation
- 关于Steam 教育的知识整理
- How to recover deleted data in disk
- Geotrust OV Multi - Domain Domain SSL Certificate rmb2100 per year contains several Domain names?
- 缓存一致性解决方案——改数据时如何保证缓存和数据库中数据的一致性
- Unity particle Foundation
- win11安装pytorch-gpu遇到的坑
- One click generation and conversion of markdown directory to word format
- [improvement class] st table to solve the interval maximum value problem [2]
- TypeScript函数详解
猜你喜欢
MySQL table insert Chinese change? Solution to the problem of No
CY7C68013A之keil编译代码
Acelems Expressway microgrid energy efficiency management platform and intelligent lighting solution intelligent lighting tunnel
Analyzing the hands-on building tutorial in children's programming
What data does the main account of Zhengda Meiou 4 pay attention to?
[high speed bus] Introduction to jesd204b
洛谷入门3【循环结构】题单题解
06 decorator mode
Free drawing software recommended - draw io
记录一次Unity 2020.3.31f1的bug
随机推荐
Acelems Expressway microgrid energy efficiency management platform and intelligent lighting solution intelligent lighting tunnel
[improvement class] st table to solve the interval maximum value problem [2]
Rhcsa --- work on the third day
[understand one article] FD_ Use of set
2022-003arts: recursive routine of binary tree
Oracle stored procedure and job task setting
June book news | 9 new books are listed, with a strong lineup and eyes closed!
LM09丨费雪逆变换反转网格策略
Steam教育的实际问题解决能力
Application of intelligent robot in agricultural ecology
将光盘中的cda保存到电脑中
Pit encountered in win11 pytorch GPU installation
Exposure X8 Standard Version picture post filter PS, LR and other software plug-ins
Arbre binaire pour résoudre le problème (2)
Ognl和EL表达式以及内存马的安全研究
Use of Baidu map
How to modify data file path in DM database
DMA Porter
win11安装pytorch-gpu遇到的坑
Ruby replaces gem Alibaba image