Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fea167e

Browse filesBrowse files
committed
Added example of Euler Totient to Math directory
1 parent 72a0e4e commit fea167e
Copy full SHA for fea167e

File tree

Expand file treeCollapse file tree

3 files changed

+63
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+63
-0
lines changed

‎Math/EulerTotient.java

Copy file name to clipboard
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
public int EulerTotient( int number )
2+
{
3+
int k, divisor;
4+
int gcd = 1;
5+
int totiatives = 0;
6+
7+
// Check all numbers, k, inclusively between 1 and number
8+
for( k = 1; k <= number; k++ )
9+
{
10+
11+
// Check all divisors of k
12+
for( divisor = 1; divisor < k; divisor++ )
13+
{
14+
15+
// Find greatest common denominator of (n, k)
16+
if( k % divisor == 0 && number % divisor == 0 )
17+
{
18+
gcd = divisor;
19+
}
20+
}
21+
22+
// If gcd is relatively prime, we have found a totient
23+
if( gcd == 1 )
24+
{
25+
totiatives++;
26+
}
27+
28+
}
29+
30+
return totiatives;
31+
}

‎Math/EulerTotientExample.class

Copy file name to clipboard
446 Bytes
Binary file not shown.

‎Math/EulerTotientExample.java

Copy file name to clipboard
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
public int EulerTotient( int number )
3+
{
4+
int k, divisor;
5+
int gcd = 1;
6+
int totiatives = 0;
7+
8+
// Check all numbers, k, inclusively between 1 and number
9+
for( k = 1; k <= number; k++ )
10+
{
11+
12+
// Check all divisors of k
13+
for( divisor = 1; divisor < k; divisor++ )
14+
{
15+
16+
// Find greatest common denominator of (n, k)
17+
if( k % divisor == 0 && number % divisor == 0 )
18+
{
19+
gcd = divisor;
20+
}
21+
}
22+
23+
// If gcd is relatively prime, we have found a totient
24+
if( gcd == 1 )
25+
{
26+
totiatives++;
27+
}
28+
29+
}
30+
31+
return totiatives;
32+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.