Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Euler_toitent_function.md",
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "dP9LH9ODdmir"
},
"source": [
"# **EULER TOITENT FUNCTION:**"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "UCesKC4Jd6yA"
},
"source": [
"Euler’s Totient function Φ (n) for an input n is the count of numbers belonging to set {1,2,3,....n} such that the number is coprime with n, i.e gcd(m,n)=1 such that 1<=m<n."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "45B_hNXcefjl"
},
"source": [
"**PROPERTIES:**\n",
"\n",
"\n",
"1. Φ (n)= n*(1-1/p1)*(1-1/p2)....*(1-1/pk), where p1,p2 .....,pk are prime factors of n.\n",
"\n",
"2. Φ (p)=p-1, where p=prime number\n",
"\n",
"3. Φ (ab)=Φ (a)*Φ (b)\n",
"\n",
"4. Φ (p^k)=(p^k)-(p^(k-1)) ,where p=prime number\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "XquPBAxYgZ3z"
},
"source": [
"**PROOF:**\n",
"\n",
"> Let n=(p1^a)*(p2^b)......*(pk^k) ,where p1,p2 .....,pk are prime factors of n and a,b,....k are powers of prime factors of n.\n",
"\n",
"\n",
"> Then, Φ (n)=Φ ((p1^a)*(p2^b)......*(pk^k))\n",
"\n",
"> Using The Properties we get: Φ (n)= Φ ((p1^a))*Φ ((p2^b))*.....Φ ((pk^k)),\n",
"\n",
"\n",
"> Since,p1,p2,...pk are prime numbers Therefore,Using the Properties Φ (pi^x)=(pi^x)-(pi^(x-1))\n",
"\n",
"\n",
"> => Φ (pi^x) = (pi^x)*(1-1/pi)\n",
"\n",
"> => Φ (n)= ((p1^a)*(1-1/p1))*((p2^b)*(1-1/p2))*........((pk^k)*(1-1/pk))\n",
"\n",
"\n",
"> => Φ (n) = ((p1^a)*(p2^b)......*(pk^k))*(1-1/p1)*(1-1/p2)*.....(1-1/pk)\n",
"\n",
"\n",
"> Therefore, Φ (n) = n*(1-1/p1)*(1-1/p2)*.....(1-1/pk)\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "cc--D9uuj10W"
},
"source": [
"**FUNCTION TO CALCULATE EULER TOTIENT FUNCTION FOR A NATURAL NUMBER N:**"
]
},
{
"cell_type": "code",
"metadata": {
"id": "Ku3SKXSEkFZN"
},
"source": [
"int euler_totient_function(int n){\n",
" int phi[n+1];\n",
" for(int i=1;i<=n;i++){\n",
" phi[i]=i;\n",
" }\n",
" for(int i=2;i<=n;i++){\n",
" if(phi[i]==i){\n",
" phi[i]=i-1;\n",
" for(int j=2*i;j<=n;j+=i){\n",
" phi[j]=(phi[j]*(i-1))/i;\n",
" }\n",
" }\n",
" }\n",
" return phi[n];\n",
"}"
],
"execution_count": null,
"outputs": []
}
]
}