当前位置:网站首页>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;
}
边栏推荐
- Win10 disk management compressed volume cannot be started
- Acelems Expressway microgrid energy efficiency management platform and intelligent lighting solution intelligent lighting tunnel
- C - derived classes and constructors
- DC-1靶场搭建及渗透实战详细过程(DC靶场系列)
- win10 磁盘管理 压缩卷 无法启动问题
- 缓存一致性解决方案——改数据时如何保证缓存和数据库中数据的一致性
- 解析少儿编程中的动手搭建教程
- Rhcsa --- work on the fourth day
- Mouse events in JS
- 解决:代理抛出异常错误
猜你喜欢

C language practice - number guessing game

Gin framework learning code

Alibaba cloud polkit pkexec local rights lifting vulnerability

Precipitate yourself and stay up late to sort out 100 knowledge points of interface testing professional literacy

Social media search engine optimization and its importance

Unity particle Foundation

记录一次Unity 2020.3.31f1的bug

One click generation and conversion of markdown directory to word format

缓存一致性解决方案——改数据时如何保证缓存和数据库中数据的一致性
![[bus interface] Axi interface](/img/ee/95ade7811ec2c37fb67a77f0b6ae2a.jpg)
[bus interface] Axi interface
随机推荐
初学爬虫-笔趣阁爬虫
06 装饰(Decorator)模式
Why can't you remember when reading? Why can't you remember- My technology learning methodology
Geotrust OV Multi - Domain Domain SSL Certificate rmb2100 per year contains several Domain names?
二叉树解题(二)
LeetCode-对链表进行插入排序
I sorted out some basic questions about opencv AI kit.
A new attribute value must be added to the entity entity class in the code, but there is no corresponding column in the database table
DC-1靶场搭建及渗透实战详细过程(DC靶场系列)
缓存一致性解决方案——改数据时如何保证缓存和数据库中数据的一致性
Interview question: do you know the difference between deep copy and shallow copy? What is a reference copy?
cs架构下抓包的几种方法
Keil compilation code of CY7C68013A
Unit testing classic three questions: what, why, and how?
Realize the function of data uploading
One click generation and conversion of markdown directory to word format
Mysql database learning
Knowledge arrangement about steam Education
Gin framework learning code
将光盘中的cda保存到电脑中

Simplify to :

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