ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1014. Product of Digits

Proper hints for all the test cases out there
Posted by samio 21 Feb 2020 00:34
This problem can be solved using greedy technic.
Method is to divide the given number from 9 to 2. Each time we will continue to divide and update the number as we go. We will keep dividing N with the same number utill its impossible to do so.And for each division we will save the number which was divisible by given number. And by "save" i mean pushing the number in a stack or a in a vector or an array. If you are using other than stack you might print out the numbers in a reverse manner.

And when we are getting "-1"?
I already wrote that, we keep updating the number. so after we pass the 9 to 2 loop, we should be left with a value of 1 in the variable N ( given number ). Incase N!=1 we are just printing "-1".

For the case N=1 or N=0? for the case 1 you should just print "1" and for the case 0 print "10", we can not print 01 since this refers to number, 1.

If you have problem understanding what i have just written or for better understanding, give this a go : https://ideone.com/709cog

Edited by author 21.02.2020 00:34

Edited by author 21.02.2020 00:38

Edited by author 21.02.2020 00:41