Simply think this problem,
Determine multiplied result of two three-digit numbers a and b is palindrome number and take largest palindrome number.
However, In order to get largest palindrome number, we have to multiply all three-digit numbers each, and the complexitcity can be 100 million order.
So I implemented the algorithm,
1) Generate 6 digit palindron numbers ordered from large to small. (up to 900 complexity)
2) Check if the number can be expressed as the product of two three digits numbers (up to 900)
Although the first and the second end is similar order does not, in fact, is a lot of difference.
The first algorithm is required for this process again to obtain the maximum value. However, the second algorithm, the result is the maximum value that the first match.
Gritty display the program, as follows: Three-digit number that can be multiplied by a for loop to determine Add a few unexpected. The smaller the size you would lose a lot of symmetry. Not because it is actually a dog up to 900 square roots. I can see that far fewer.
int main() { for( int n = 997 ; n > 100 ; n-- ) { int v = n * 1000 + (n/100) + ((n/10)%10)*10 + (n%10)*100; for( int i = (v+998)/999 ; i*i <= v ; i++ ) { if( v%i == 0 ) { printf("%dx%d = %d\n", i, v/i, v); return 0; } } } }
'Programming > Project Euler' 카테고리의 다른 글
6. Project Euler #6 : Sum square difference (0) | 2015.02.13 |
---|---|
5. Project Euler #5 : The smallest number that can be divided by numbers below 20. (0) | 2015.01.29 |
3. Project Euler #3 : Find the biggest prime factor. (0) | 2015.01.20 |
[C/C++] Project Euler #2 : Sum of even terms of Fibonacci(Dynamic Programming) (0) | 2015.01.20 |
[C/C++] Project Euler #1 Add 3 or 5 multipliers. (0) | 2015.01.19 |