Skip to content

Commit bbd14fb

Browse files
committed
euler totient function added
1 parent 585954c commit bbd14fb

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int phi(int n) {
5+
int result = n;
6+
for (int i = 2; i * i <= n; i++) {
7+
if(n % i == 0) {
8+
while(n % i == 0)
9+
n /= i;
10+
result -= result / i;
11+
}
12+
}
13+
if(n > 1)
14+
result -= result / n;
15+
return result;
16+
}
17+
18+
int main()
19+
{
20+
int n;
21+
cin >> n;
22+
cout << "The number of coprimes less than n are " << phi(n) << endl;
23+
}

0 commit comments

Comments
 (0)