EgyptianFraction

204 days ago by jgdelk

def isEgyptian(a, b, c, n ): if (4 * a * b * c) / (a * b + b * c + a * c) == n: return true def findEgyptianFractions(n): results = [] for a in range(1, 1 + ceil(3 * n / 4)): if (a * 4 - n) != 0: for b in range(1, 1 + ceil(2 * a * n / (4 * a - n))): if n != (4 * a * b) / (a + b): for c in range(1, 1 + ceil(a * b * n / (4 * a * b - a * n - b * n))): if isEgyptian(a, b, c, n): if ((c >= b) and (b >= a)): results.append([a, b, c]) return results def countEgyptianFractions(n): count = 0 for a in range(1, 1 + ceil(3 * n / 4)): if (a * 4 - n) != 0: for b in range(1, 1 + ceil(2 * a * n / (4 * a - n))): if n != (4 * a * b) / (a + b): for c in range(1, 1 + ceil(a * b * n / (4 * a * b - a * n - b * n))): if isEgyptian(a, b, c, n): if ((c >= b) and (b >= a)): count += 1 return count # Generate Data for growth rate plot resultsList = [] for n in range(2, 50): print(n) resultsList.append([n, countEgyptianFractions(n)]) 
       
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
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
def findEgyptianFractionsFaster(n): results = [] for a in range(ceil((n + 1) / 4), 1 + ceil(3 * n / 4)): if ((a * 4 - n) != 0) and ((4 * a - n) != 0): for b in range(ceil(n * a / (4 * a - n)), 1 + ceil(2 * a * n / (4 * a - n))): if n != (4 * a * b) / (a + b): for c in range(1, 1 + ceil(a * b * n / (4 * a * b - a * n - b * n))): if isEgyptian(a, b, c, n): if ((c >= b) and (b >= a)): results.append([a, b, c]) return results def countEgyptianFractionsFaster(n): count = 0 for a in range(ceil((n + 1) / 4), 1 + ceil(3 * n / 4)): if ((a * 4 - n) != 0) and ((4 * a - n) != 0): for b in range(ceil(n * a / (4 * a - n)), 1 + ceil(2 * a * n / (4 * a - n))): if n != (4 * a * b) / (a + b): for c in range(1, 1 + ceil(a * b * n / (4 * a * b - a * n - b * n))): if isEgyptian(a, b, c, n): if ((c >= b) and (b >= a)): count += 1 return count findEgyptianFractionsFaster(4) 
       
[[2, 3, 6], [2, 4, 4], [3, 3, 3]]
[[2, 3, 6], [2, 4, 4], [3, 3, 3]]
# Generate Data for growth rate plot resultsList = [] for n in range(2, 50): print(n) resultsList.append([n, countEgyptianFractionsFaster(n)]) 
       
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
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
list_plot(resultsList) 
       
findEgyptianFractions(4) 
       
[[2, 3, 6], [2, 4, 4], [3, 3, 3]]
[[2, 3, 6], [2, 4, 4], [3, 3, 3]]
print(resultsList) 
       
[[2, 1], [3, 3], [4, 3], [5, 2], [6, 8], [7, 7], [8, 10], [9, 6], [10,
12], [11, 9], [12, 21], [13, 4], [14, 17], [15, 39], [16, 28], [17, 4],
[18, 26], [19, 11], [20, 36], [21, 29], [22, 25], [23, 21], [24, 57],
[25, 10], [26, 20], [27, 29], [28, 42], [29, 7], [30, 81], [31, 19],
[32, 70], [33, 31], [34, 25], [35, 65], [36, 79], [37, 9], [38, 32],
[39, 73], [40, 96], [41, 7], [42, 86], [43, 14], [44, 62], [45, 93],
[46, 42], [47, 34], [48, 160], [49, 18]]
[[2, 1], [3, 3], [4, 3], [5, 2], [6, 8], [7, 7], [8, 10], [9, 6], [10, 12], [11, 9], [12, 21], [13, 4], [14, 17], [15, 39], [16, 28], [17, 4], [18, 26], [19, 11], [20, 36], [21, 29], [22, 25], [23, 21], [24, 57], [25, 10], [26, 20], [27, 29], [28, 42], [29, 7], [30, 81], [31, 19], [32, 70], [33, 31], [34, 25], [35, 65], [36, 79], [37, 9], [38, 32], [39, 73], [40, 96], [41, 7], [42, 86], [43, 14], [44, 62], [45, 93], [46, 42], [47, 34], [48, 160], [49, 18]]
# Generate Data for growth rate plot primeResultsList = [] for n in srange(2, 50): if n.is_prime(): print(n) primeResultsList.append([n, countEgyptianFractionsFaster(n)]) 
       
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
# Plot Result list_plot(resultsList, color='blue') + list_plot(primeResultsList, color='red') 
       
# Generate Data for growth rate plot primeResultsList = [] mod1List = [] mod2List = [] mod3List = [] mod4List = [] mod5List = [] mod6List = [] mod7List = [] for n in srange(2, 50): x = countEgyptianFractionsFaster(n) print(n) if n.is_prime(): primeResultsList.append([n, x])