One such permutation..!
Practice
5 (1 votes)
Medium
Strings
Simple Math
Problem
82% Success 140 Attempts 30 Points 0.5s Time Limit 256MB Memory 1024 KB Max Code

This is (probably) the most easiest question of the problem set..!

You will be given a number say 'X'. You just have to find out one of its permutation that is divisible by 16.

Now this is to clarify what permutation means:

Suppose you are given 'X' as '123' then all possible permutations are: '123', '132', '213', '231', '312', '321'.

Just one twist though..

You need to output the lexicographically smallest permutation of 'X' that is divisible by 16.

Note: Your smallest permutation should not start with '0' (Technically, NO LEADING ZEROES ALLOWED...!!)

Note: If there are no such permutations that are divisible by 16 then, output "-1".


Input format:

First line contains 'X' as a string. All characters will be digits from 0 to 9 inclusive.


Output format:

Output "-1", if no such permutation exists.

else Output smallest permutation with no leading zeroes.


Constraints:

1 <= X <= 100. (Note that this means 'X' can be maximum '100' digits long number..!)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
13 votes
Tags:
Binary search algorithmMediumRecruitPrime FactorizationSegment treeMathematicsOpenApprovedMathematicsMathamatics
Points:30
5 votes
Tags:
Basic MathC++Math
Points:30
4 votes
Tags:
Medium