Created
February 15, 2017 15:32
-
-
Save mame-n/b899c9a9bce31690145e7423992d5f20 to your computer and use it in GitHub Desktop.
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
class P69 | |
MAXN = 1000000 | |
def initialize(n = MAXN) | |
@n = n | |
end | |
def main | |
phis = phis( @n ) | |
phis.index( max_phi( phis ) ) + 1 | |
end | |
def max_phi( phis ) | |
phis.inject do |max,phi| | |
max < phi ? phi : max | |
end | |
end | |
def phis( k ) | |
(1..k).map do |n| | |
n/phi(n).to_f | |
end | |
end | |
def phi(n) | |
n.downto(1).select do |i| | |
n.gcd(i) == 1 | |
end.size | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment