-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheuler243.go
134 lines (118 loc) · 2.38 KB
/
euler243.go
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package main
import (
"fmt"
"github.com/blevz/euler/common"
_ "math"
)
//Need to use principle of inclusion exclusion
type PFact struct {
//Maps the prime factor with its exponent in the primefactorization
data map[int]int
}
func (p PFact) Int() int {
product := 1
for k, v := range p.data {
for x := 0; x < v; x++ {
product *= k
}
}
return product
}
func (p *PFact) SetFactorial(num, exp int) {
p.data[num] = exp
}
func Make_PFact() *PFact {
var p PFact
p.data = make(map[int]int)
return &p
}
func gcd(a, b int) int {
for a != 0 {
c := a
a = b % a
b = c
}
return b
}
func getResilentNumerators(denom int) int {
m := make(map[int]struct{})
primeFactorMap := common.PrimeFactorizationMap(denom)
for k, _ := range primeFactorMap {
for x := k; x < denom; x += k {
m[x] = struct{}{}
}
}
return denom - len(m) - 1
}
func getResilence(denom int) float64 {
resilentNumerators := getResilentNumerators(denom)
r := float64(resilentNumerators) / float64(denom-1)
return r
}
func getResilentNumeratorsP(p *PFact) int {
val := p.Int()
num := val
for k, _ := range p.data {
num = num * (k - 1) / k
}
return num
}
func getResilenceP(p *PFact) float64 {
resilentNumerators := getResilentNumeratorsP(p)
r := float64(resilentNumerators) / float64(p.Int()-1)
return r
}
func main() {
fmt.Println(float64(15499) / float64(94744))
//
p := Make_PFact()
p.SetFactorial(2, 3)
p.SetFactorial(3, 1)
p.SetFactorial(5, 1)
p.SetFactorial(7, 1)
p.SetFactorial(11, 1)
p.SetFactorial(13, 1)
p.SetFactorial(17, 1)
p.SetFactorial(19, 1)
p.SetFactorial(23, 1)
fmt.Println(p.Int())
r := getResilenceP(p)
fmt.Println(r)
if r < float64(15499)/float64(94744) {
fmt.Println("fin", p.Int(), r)
}
//for x := 0; x < math.MaxInt32; x++ {
/*minR := float64(1)
for x := 2; x < math.MaxInt32; x++ {
if !common.IsPrime(x) {
p := Make_PFact()
p.data = common.PrimeFactorizationMap(x)
r := getResilenceP(p)
if r < minR {
minR = r
fmt.Println(x)
}
if r < float64(15499)/float64(94744) {
//if r < float64(4)/float64(10) {
fmt.Println(x, r)
break
}
}
}*/
/*
fmt.Println(float64(15499) / float64(94744))
c := make(chan int)
go common.GenPrimes(c)
num := 1
minR := float64(1)
for x := range c {
fmt.Println(num)
num *= x
r := getResilence(num)
if r < .2 {
minR = r
fmt.Println(num, r)
}
}
fmt.Println(minR)*/
}