Created
December 15, 2011 22:00
-
-
Save buccolo/1483107 to your computer and use it in GitHub Desktop.
Euler Phi (n)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'rational' | |
number = ARGV[0].to_i | |
current = 0 | |
phi = 0 | |
while (current < number) | |
if (number.gcd(current) == 1) | |
phi = phi + 1 | |
end | |
current = current + 1 | |
end | |
puts phi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment