-
Notifications
You must be signed in to change notification settings - Fork 0
/
primos.rb
77 lines (41 loc) · 771 Bytes
/
primos.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
class Mat
def verprimo(num)
num = num.to_i
if (num < 2)
puts "numero deve ser maior que 1"
exit
end
raiz = Math.sqrt(num)
raiz = raiz.to_i + 1
ret = true
for ct in (2..raiz)
if (num % ct == 0 && num != ct)
ret = false
break
end
end
return ret
end
def fatores(num)
num = num.to_i
array_divisiveis = Array.new([])
for x in 2..num
if num % x == 0
array_divisiveis.push(x)
end
end
array_primos = Array.new([])
for d in array_divisiveis
if self.verprimo(d) == true
array_primos.push(d)
end
end
return array_primos
end
def fatores_do_mmc(num,array_primos)
array_primos.sort
end
end
@vamo = Mat.new
x = @vamo.fatores(100)
puts x