-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem129.rb
More file actions
executable file
·28 lines (25 loc) · 844 Bytes
/
problem129.rb
File metadata and controls
executable file
·28 lines (25 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# A number consisting entirely of ones is called a repunit. We shall define R(k) to be a repunit of length k; for example, R(6) = 111111.
#
# Given that n is a positive integer and GCD(n, 10) = 1, it can be shown that there always exists a value, k, for which R(k) is divisible by n, and let A(n) be the least such value of k; for example, A(7) = 6 and A(41) = 5.
#
# The least value of n for which A(n) first exceeds ten is 17.
#
# Find the least value of n for which A(n) first exceeds one-million.
def a(n)
return nil if n % 2 == 0 or n % 5 == 0
count = 1
current = 1
while current != 0
count += 1
current = (current * 10 + 1) % n
end
return count
end
max = 10**6
current = max + 1 #it is obvious that A(n) <= n
while true
temp = a(current)
puts "#{current}, #{temp}"
break if temp != nil and temp > max
current += 2
end