euler's totient function c++
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
- initialize int c++
- Category
- C++
- Title
- how do for loops on c++
- Category
- C++
- Title
- how to iterate trough a vector in c++
- Category
- C++
- Title
- check for bst
- Category
- C++
- Title
- lambda operator in c++
- Category
- C++
- Title
- passing a vector to a function c++
- Category
- C++
- Title
- C++ remove element from set
- Category
- C++
- Title
- find_if c++
- Category
- C++
- Title
- length of string c++
- Category
- C++
- Title
- case label in c++
- Category
- C++
- Title
- C++ int to char*
- Category
- C++
- Title
- trovare il valore massimo in un array c++ w3
- Category
- C++
- Title
- c++ how to loop through a vector but not the last element
- Category
- C++
- Title
- get elements of 2d array c++
- Category
- C++
- Title
- how to run c++ file mingw cmd
- Category
- C++
- Title
- how to create a vector in c++
- Category
- C++
- Title
- range based for loop c++ with reference
- Category
- C++
- Title
- longest common subsequence
- Category
- C++
- Title
- how to avoid tle in c++
- Category
- C++
- Title
- opencv compile c++
- Category
- C++
- Title
- c++ for loops
- Category
- C++
- Title
- std::reverse
- Category
- C++
- Title
- powers of 2 in cpp
- Category
- C++
- Title
- program to know if a number is prime
- Category
- C++
- Title
- is TLE means my code is correct but taking more time to computr
- Category
- C++
- Title
- generate random double c++
- Category
- C++
- Title
- dijkstra c++ geeksforgeeks using set
- Category
- C++
- Title
- filling 2d array with 0 c++
- Category
- C++
- Title
- removing repeated characters in a string c++
- Category
- C++
- Title
- create a dictionary cpp
- Category
- C++
- Title
- opperanf >> c++
- Category
- C++
- Title
- c++ get ascii value of char
- Category
- C++
- Title
- converting char to int in c++
- Category
- C++
- Title
- how to load from files C++
- Category
- C++
- Title
- c++ while true loop
- Category
- C++
- Title
- fast input output in c++
- Category
- C++
- Title
- fmod c++
- Category
- C++
- Title
- how to grab all of user input c++
- Category
- C++
- Title
- variadic templates
- Category
- C++
- Title
- zeros of array c++
- Category
- C++
- Title
- nearest integer rounding in c++
- Category
- C++
- Title
- c++ ros subscriber
- Category
- C++
- Title
- advanced c++ topics
- Category
- C++
- Title
- *min_element in c++
- Category
- C++
- Title
- loop c++
- Category
- C++
- Title
- How to find the kth smallest number in cinstant space
- Category
- C++
- Title
- pionter in c++
- Category
- C++
- Title
- knapsack
- Category
- C++
- Title
- substitution failure is not an error
- Category
- C++
- Title
- c++ program for addition of two numbers using functions
- Category
- C++
- Title
- binary tree deletion
- Category
- C++
- Title
- for c++
- Category
- C++
- Title
- Newton's sqrt in c++
- Category
- C++
- Title
- c++ ros publisher
- Category
- C++
- Title
- stack function in cpp
- Category
- C++
- Title
- & in xml
- Category
- C++
- Title
- how to open an input file in c++
- Category
- C++
- Title
- how to compare lower case character to uppercase cpp
- Category
- C++
- Title
- map arduino
- Category
- C++
- Title
- print matrix c++
- Category
- C++
- Title
- if esle in c++
- Category
- C++
- Title
- declaring 2d vector in c++
- Category
- C++
- Title
- C++ If
- Category
- C++
- Title
- map.erase in c++
- Category
- C++
- Title
- how to declare a function in c++
- Category
- C++
- Title
- date to string c++
- Category
- C++
- Title
- c++ ambigous error
- Category
- C++
- Title
- sort function in cpp
- Category
- C++
- Title
- c++ string to vector int
- Category
- C++
- Title
- SFML window
- Category
- C++
- Title
- how to delete a node c++
- Category
- C++
- Title
- how to turn int into string c++
- Category
- C++
- Title
- how to use a new node c++
- Category
- C++
- Title
- c++ char define
- Category
- C++
- Title
- what is difference between ciel and floor
- Category
- C++
- Title
- how to make a 2d vector in c++
- Category
- C++
- Title
- array<string, 7> c++
- Category
- C++
- Title
- string substr c++
- Category
- C++
- Title
- Find the duplicate in an array of N integers.
- Category
- C++
- Title
- c++ string to integer without stoi
- Category
- C++
- Title
- c++ allocate dynamic with initial values
- Category
- C++
- Title
- what is atoi in strinf
- Category
- C++
- Title
- initialize 2d array c++
- Category
- C++
- Title
- how to execute c++ program in cmd
- Category
- C++
- Title
- sort a string alphabetically c++
- Category
- C++
- Title
- calculate sum in c++
- Category
- C++
- Title
- check if key exists in map c++
- Category
- C++
- Title
- border radius layout android xml
- Category
- C++
- Title
- what is a header in c++
- Category
- C++
- Title
- c++ function to find minimum element in array
- Category
- C++
- Title
- RLE Encoding/Compression c++
- Category
- C++
- Title
- 2d vector
- Category
- C++
- Title
- mao two drivers c++
- Category
- C++
- Title
- compare function in sort c++ stl
- Category
- C++
- Title
- find in set of pairs using first value cpp
- Category
- C++
- Title
- formal parameter c++
- Category
- C++
- Title
- set of vectors c++
- Category
- C++
- Title
- find all the palindrome substring in a given string
- Category
- C++
- Title
- c++ cout int
- Category
- C++
- Title
- time conversion hackerrank solution in c++
- Category
- C++