Sort 39 Discussions, By:
Please Login in order to post a comment
first problem where you don't need to apply any logic to speed up your code. :)
Kind-of. You just need to think about minimums and maximums.
For custom input, n=19, i am getting an approximate answer only even after converting power (double) to BigInteger.
The exponential notation when printed removes some digits from last.
Finally realize , I have to make my own power function
It's just a implementation which loops from 1 to 9 to check the length of pow(i, N). Doesn't even need to store or sort the answers. The funny part at the beginning is to observe the growth of the number of digits for different powers, and the rest is trivial. Frankly, the original problem is more interesting, as you can also observe that all except are invalid answers.
Just use basic maths and your code reduces further.
for i in range(a,10):
i really think this is the easiest project euler i have been doing so far. Just try for N=1,2,3 and understand what's going on.
If you program in C++ then make sure you use unsigned long long. The last test case might fail if define your variables as long long only.
At first I built my own magnitude function to determine the number of digits in a number but I realized that log10() does the job quite well.
This problem is as simple as brute forcing the math and keeping a list of n values and their corresponding answers. There are only 47 values but that's all I'll say, otherwise I would ruin this challenge for everyone.
Just write your own pow function if you are using python! It did the trick!
I didn't need to write any functions in python. Just looped over bases 1-9 and exponents 1-21 which yields all the 47 answers by only looping 189 times. And to even further improve performance, I kept a literal with a dictionary with lists for each N.
Really interesting problem. Although at first time I need to run manually to check the patterns. Anyway, this can be solved without calculating the power at all. My code finishes all of test case with 0s. You just need to know the minimum of X, which if X^n will have number of digits more than n. You just need to calculate between [1..X-1] and calculate based on input n.