Greatest Product
Time limit1sMemory limit128 MB
Given N up to two billion, find the largest product of digits over all integers from 1 to N.
- Level
Medium6 of 10
- Topics
- Greedy, Math, Implementation
- Solved
- No attempts yet
Problem
September 10th is Forest Day. To celebrate, the dwellers of the Magic Forest decided to throw a party, and Kuzma the beaver was put in charge of the intellectual games. The rules of the game Kuzma invented are simple.
The host announces a positive integer . For every positive integer from to , the player computes the product of that integer's digits, and must report the greatest such product.
To run the game smoothly, all answers must be known in advance. This is tricky because can be fairly large (). Since Kuzma is not comfortable with computers, write a program that, given a positive integer , finds the correct answer.
In other words, over all integers with , output the maximum possible product of the digits of .
Input
Each line of the input contains one integer . The input may span several lines until end of file (EOF). ()
Output
For each , print on the corresponding line the greatest digit product among the integers from to .