当前位置:网站首页>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;
}
边栏推荐
- The underlying principle of go map (storage and capacity expansion)
- Cache consistency solution - how to ensure the consistency between the cache and the data in the database when changing data
- LeetCode-对链表进行插入排序
- Let genuine SMS pressure measurement open source code
- Use of Baidu map
- CorelDRAW graphics suite2022 free graphic design software
- 6月书讯 | 9本新书上市,阵容强大,闭眼入!
- Cannot activate CONDA virtual environment in vscode
- Pytest learning ----- pytest assertion of interface automation testing
- Markdown编辑语法
猜你喜欢

Thinkphp内核工单系统源码商业开源版 多用户+多客服+短信+邮件通知

Mysql database learning

Online incremental migration of DM database

Analyzing the hands-on building tutorial in children's programming

Detailed process of DC-1 range construction and penetration practice (DC range Series)

解析少儿编程中的动手搭建教程

June book news | 9 new books are listed, with a strong lineup and eyes closed!

Markdown编辑语法

农业生态领域智能机器人的应用

Orthogonal test method and function diagram method for test case design
随机推荐
I sorted out some basic questions about opencv AI kit.
正大留4的主账户信息汇总
C# 图片显示占用问题
Getting started with pytest ----- confitest Application of PY
Introduction to Luogu 3 [circular structure] problem list solution
解决:代理抛出异常错误
MySQL table insert Chinese change? Solution to the problem of No
LM09丨费雪逆变换反转网格策略
二叉树解题(一)
VMware installation win10 reports an error: operating system not found
Alibaba cloud polkit pkexec local rights lifting vulnerability
oracle 存储过程与job任务设置
C language practice - number guessing game
Research on the security of ognl and El expressions and memory horse
C# 基于MQTTNet的服务端与客户端通信案例
Ruby replaces gem Alibaba image
[Yu Yue education] autumn 2021 reference materials of Tongji University
geotrust ov多域名ssl证书一年两千一百元包含几个域名?
Cannot activate CONDA virtual environment in vscode
TypeScript类的使用

Simplify to :

https://blog.csdn.net/WSY444/article/details/125496621?spm=1001.2014.3001.5502