-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem29.cs
46 lines (40 loc) · 1.39 KB
/
Problem29.cs
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
using System;
class Problem29
{
static void Main(string[] args)
{
// Maximum sequence length
int sequenceLength = 99 * 99;
// for each a^b, look for higher base representations
// We can dramatically simply this search knowing that if there are other y^z representations of a^b,
// they must satisfy
// b = log_a(y^z)
// b = z.log_a(y), where y and z are integers
for (int a = 2; a <= 10; a++)
{
for (int b = 2; b <= 100; b++)
{
// Begin the search for any higher base representations of a^b
// for each power of the base <= 100
int pow = 2;
int y = (int) Math.Pow(a, pow);
while (y <= 100)
{
if (b % pow == 0)
{
int z = b / pow;
if (z >= 2 && z <= 100)
{
Console.WriteLine("{0}^{1} == {2}^{3}", a, b, y, z);
// evenly divides...we have our y and z
sequenceLength--;
}
}
y = (int) Math.Pow(a, ++pow);
}
}
}
Console.WriteLine("Sequence Length: {0}", sequenceLength);
Console.ReadLine();
}
}