Answer the question
In order to leave comments, you need to log in
How to use the Euler function in C++?
I can't figure out how to use it at all. I copied the int function from the book.
#include <iostream>
#include <conio.h>
using namespace std;
int phi (int n) {
int result = n;
for (int i=2; i*i<=n; ++i){
if (n % i == 0) {
while (n % i == 0)
n /= i;
result -= result / i;
}
}
if (n > 1){
result -= result / n;
}
return result;
}
int main(){
/*что-то*/
_getch();
return 0;
}
Answer the question
In order to leave comments, you need to log in
first is the phi function which returns an int. Secondly, read on Wikipedia what this function does in general, and the question will disappear.
Everything is clear, I misunderstood this Function a little.
#include <iostream>
#include <conio.h>
using namespace std;
void phi(){
int n,result;
cin >> n;
result = n;
for (int i = 2; i*i <= n; ++i){
if (n % i == 0){
while (n % i == 0){
n /= i;
}
result -= result / i;
}
}
if (n > 1){
result -= result / n;
}
cout << result;
}
int main(){
phi();
_getch();
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question