-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path47.rb
56 lines (51 loc) · 831 Bytes
/
47.rb
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'set'
def sieve(below)
total = below - 2#00000
array = [].fill(0 .. total){false}
p = 2
loop do
unless array[p - 2]
2.upto(below / p) do |x|
array[x * p - 2] = true
end
end
p += 1
break if p > total
end
result = []
array.each_index{|index|result << index + 2 unless array[index]}
Set.new(result)
end
def is_prime(n)
$primes.include?(n) ? true : false
end
def factors(n)
#s = Set.new()
num = 0
$primes.each do |x|
if x > n
break
elsif n % x == 0
num += 1
end
end
num
end
$primes = sieve(1000000)
consecutive = 0
num = 4
n = 1
loop do
if is_prime(n)
consecutive = 0
elsif factors(n) == num
consecutive += 1
if consecutive == num
p n - num + 1
exit
end
else
consecutive = 0
end
n += 1
end