Largest Lucky Number
InterviewTime limit2sMemory limit256 MB
Given N up to 1,000,000, find the largest number no greater than N whose digits are only 4s and 7s.
- Level
Easy3 of 10
- Topics
- Recursion, Brute force, Math
- Solved
- No attempts yet
Problem
A lucky number is a positive integer whose decimal representation consists only of the digits 4 and 7.
Given a natural number N, find the largest lucky number that is less than or equal to N.
Input
The first line contains a natural number N. N is at least 4 and at most 1,000,000.
Output
Print the largest lucky number that is less than or equal to N.