HACKER RANK Project Euler 04 - Largest Palindrome Product - Solution.'Py'
Project Euler Challenges-04 - Largest Palindrome Product Solution
Problem Statement
This problem is a programming version of Problem 4 from projecteuler.net
A palindromic number reads the same both ways. The smallest 6 digit palindrome made from the product of two 3-digit numbers is 101101=143×707 .
Find the largest palindrome made from the product of two 3-digit numbers which is less than N .
Input Format
First line contains T that denotes the number of test cases. This is followed by T lines, each containing an integer, N .
Output Format
Print the required answer for each test case in a new line.
Constraints
1≤T≤100
101101<N<1000000
Sample Input
2
101110
800000
Sample Output
101101
793397
Problem Statement
This problem is a programming version of Problem 4 from projecteuler.net
A palindromic number reads the same both ways. The smallest 6 digit palindrome made from the product of two 3-digit numbers is 101101=143×707 .
Find the largest palindrome made from the product of two 3-digit numbers which is less thanN .
Find the largest palindrome made from the product of two 3-digit numbers which is less than
Input Format
First line containsT that denotes the number of test cases. This is followed by T lines, each containing an integer, N .
First line contains
Output Format
Print the required answer for each test case in a new line.
Print the required answer for each test case in a new line.
Constraints
1≤T≤100
101101<N<1000000
Sample Input
2
101110
800000
Sample Output
101101
793397
Solution:
t = input()
while(t>0):
t-=1
pmax = input()
tmp = 0
for i in xrange(110 , 1000 , 11):
for j in xrange(100, 1000):
p = i*j
if p < pmax and str(p) == str(p)[::-1] and p >tmp :
x, y, tmp = i, j, p
print tmp
t = input()
while(t>0):
t-=1
pmax = input()
tmp = 0
for i in xrange(110 , 1000 , 11):
for j in xrange(100, 1000):
p = i*j
if p < pmax and str(p) == str(p)[::-1] and p >tmp :
x, y, tmp = i, j, p
print tmp
Comments
Post a Comment