Project Euler — Problem 99 Solution

Problem

Com­par­ing two num­bers writ­ten in index form like 211 and 37 is not dif­fi­cult, as any cal­cu­la­tor would con­firm that 211 = 2048 < 37 = 2187.

How­ev­er, con­firm­ing that 632382518061 > 519432525806 would be much more dif­fi­cult, as both num­bers con­tain over three mil­lion dig­its.

Using base_exp.txt (right click and ‘Save Link/Target As…’), a 22K text file con­tain­ing one thou­sand lines with a base/exponent pair on each line, deter­mine which line num­ber has the great­est numer­i­cal val­ue.

NOTE: The first two lines in the file rep­re­sent the num­bers in the exam­ple giv­en above.

Solution

This ques­tion looks tricky at first as work­ing out the actu­al val­ue of each of the base/exponent pair in the file can take a looong time.. but as many oth­ers have sug­gest­ed, you can com­pare the log­a­rithm of the actu­al val­ue instead, which can be expressed in the fol­low­ing form:

image

which can be com­put­ed very quick­ly and the rest is easy.