euler phi gfg
C++
// C program to calculate Euler's Totient Function
#include <stdio.h>
int phi(int n)
{
int result = n; // Initialize result as n
// Consider all prime factors of n and subtract their
// multiples from result
for (int p = 2; p * p <= n; ++p) {
// Check if p is a prime factor.
if (n % p == 0) {
// If yes, then update n and result
while (n % p == 0)
n /= p;
result -= result / p;
}
}
// If n has a prime factor greater than sqrt(n)
// (There can be at-most one such prime factor)
if (n > 1)
result -= result / n;
return result;
}
// Driver program to test above function
int main()
{
int n;
for (n = 1; n <= 10; n++)
printf("phi(%d) = %d\n", n, phi(n));
return 0;
}
Also in C++:
- Title
- min heap declaration in c++ stl
- Category
- C++
- Title
- c++ argv
- Category
- C++
- Title
- container class in c++
- Category
- C++
- Title
- how to delete something in an array c++
- Category
- C++
- Title
- c++ ternary operator
- Category
- C++
- Title
- C++ int to char*
- Category
- C++
- Title
- c++ convert int to double
- Category
- C++
- Title
- new in c++
- Category
- C++
- Title
- pop_back
- Category
- C++
- Title
- pionter in c++
- Category
- C++
- Title
- how to initialize a vector in c++
- Category
- C++
- Title
- properties of a set c++
- Category
- C++
- Title
- printf c++
- Category
- C++
- Title
- 1d fixed length arrays c++
- Category
- C++
- Title
- c++ typeid get type name
- Category
- C++
- Title
- c++ stack
- Category
- C++
- Title
- dijkstra c++ geeksforgeeks using set
- Category
- C++
- Title
- dijkstra in c++
- Category
- C++
- Title
- tellg and seekg c++
- Category
- C++
- Title
- Runtime Error: Runtime ErrorAbort signal from abort(3) (SIGABRT)
- Category
- C++
- Title
- how to find the mode of a vector c++
- Category
- C++
- Title
- switch c++
- Category
- C++
- Title
- convert integer to string c++
- Category
- C++
- Title
- c++ convert int to cstring
- Category
- C++
- Title
- calling by reference and pointers c++
- Category
- C++
- Title
- cout console
- Category
- C++
- Title
- compare values within within a vector c++
- Category
- C++
- Title
- how to type cast quotient of two integers to double with c++
- Category
- C++
- Title
- how to make a n*n 2d dynamic array in c++
- Category
- C++
- Title
- opperanf >> c++
- Category
- C++
- Title
- c++ compiler for sublime text
- Category
- C++
- Title
- how to compile opencv c++ in ubuntu
- Category
- C++
- Title
- map.erase in c++
- Category
- C++
- Title
- iterate 2d array c++
- Category
- C++
- Title
- how use global variables instead of local in c++
- Category
- C++
- Title
- how to get the prime number in c++ where time complexity is 0(log n)
- Category
- C++
- Title
- c++ push multiple elements to vector
- Category
- C++
- Title
- c++ random
- Category
- C++
- Title
- can you use a return to print a string when referencing an integer c++
- Category
- C++
- Title
- substr in c++
- Category
- C++
- Title
- best fit algorithm
- Category
- C++
- Title
- c++ compare char array
- Category
- C++
- Title
- preorder traversal
- Category
- C++
- Title
- registering a new QML type
- Category
- C++
- Title
- checking an int in c++
- Category
- C++
- Title
- c++ do you not inherit constructor
- Category
- C++
- Title
- body parser
- Category
- C++
- Title
- vector stl c++
- Category
- C++
- Title
- passing array to function c++ pointer
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++
- Title
- COunt the number of continous subsequences such that the sum is between
- Category
- C++
- Title
- getting a random letter in c++
- Category
- C++
- Title
- runtime error in c++
- Category
- C++
- Title
- simple timer arduino blynk library error
- Category
- C++
- Title
- static variable in c++
- Category
- C++
- Title
- print type cpp
- Category
- C++
- Title
- select elements from array C++
- Category
- C++
- Title
- arrow operator c++
- Category
- C++
- Title
- pbds in c++
- Category
- C++
- Title
- command line options in c++
- Category
- C++
- Title
- How to check if a triangular cycle exists in a graph
- Category
- C++
- Title
- c++ sort array of ints
- Category
- C++
- Title
- delete 2d dynamic array c++
- Category
- C++
- Title
- c++ initialise array
- Category
- C++
- Title
- convert stirng to int c++
- Category
- C++
- Title
- converting char to int in c++
- Category
- C++
- Title
- how to check the datatype of a variable in c++
- Category
- C++
- Title
- recursive in c++
- Category
- C++
- Title
- how initilaize deffult value to c++ class
- Category
- C++
- Title
- binary search in set c++
- Category
- C++
- Title
- how to delete a node c++
- Category
- C++
- Title
- c++ program to input and print text using Dynamic Memory Allocation.loop
- Category
- C++
- Title
- binary exponentiation
- Category
- C++
- Title
- and or in c++
- Category
- C++
- Title
- log base 10 c+_+
- Category
- C++
- Title
- cin.ignore
- Category
- C++
- Title
- zeros of array c++
- Category
- C++
- Title
- c++ string to stream
- Category
- C++
- Title
- how to make a switch case statement in c++
- Category
- C++
- Title
- how to open an input file in c++
- Category
- C++
- Title
- get line C++
- Category
- C++
- Title
- const in c++
- Category
- C++
- Title
- sieve of eratosthenes c++
- Category
- C++
- Title
- remove element by index from vector c++
- Category
- C++
- Title
- making random numbers in c++
- Category
- C++
- Title
- Insert into vector C++
- Category
- C++
- Title
- constant variables in c++
- Category
- C++
- Title
- variable sized arrays hackerrank solution in c++
- Category
- C++
- Title
- apple and orange hackerrank solution in c++
- Category
- C++
- Title
- -> cpp
- Category
- C++
- Title
- merge sort in c++
- Category
- C++
- Title
- catalan number calculator
- Category
- C++
- Title
- roscpp publish int32
- Category
- C++
- Title
- how to define a while statement in c++
- Category
- C++
- Title
- range of int
- Category
- C++
- Title
- c++ how to use scanf
- Category
- C++
- Title
- c++ function to find minimum element in array
- Category
- C++
- Title
- c++ how to get a random number
- Category
- C++
- Title
- add two numbers in c++
- Category
- C++
- Title
- what is meaning of bus error in compattive programming
- Category
- C++