Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tips to solve problem #41 of project euler

I'm trying to solve Problem 41of project Euler in Java, by counting the number from 99888888 to 80000000(which took very long time :( ), I got 98765431 as an answer, but I'm getting that answer not correct. Could anyone please tell me the reason of not getting the correct answer and how can I speed my program?

like image 488
Jazzy Avatar asked Jan 17 '10 13:01

Jazzy


1 Answers

A pandigital number doesn't needs to contain all numbers from 1 to 9, but all from 1 to length.

So, you'll need to try all permutations from 1 to 9 starting with 1 digit and going up, filtering all prime numbers and, then, taking largest one.

like image 196
Rubens Farias Avatar answered Oct 13 '22 12:10

Rubens Farias