eolymp
bolt
Try our new interface for solving problems
Məsələlər

George Lucas and 1138

George Lucas and 1138

\includegraphics{https://static.e-olymp.com/content/86/86a310a6f3e8aac7af7ffc21953a7d3e9338df52.jpg} It's well known in Star Wars culture that George Lucas was preoccupied with the number \textbf{1138}. \textbf{THX 1138} is the title of his first movie, and-according to Wookieepedia: The Star Wars Wiki-George Lucas liked to reuse key words and numbers in later films as a way of unifying all of his works. If you're up on your Star Wars trivia, then you know that in Episode V a prisoner was transferred from cell block 1138. In Episode II, all clone troopers have the number \textbf{1138} prominently displayed on the back of their helmets. And if you type in \textbf{1138} while viewing the Episode III DVD, you immediately advance to the scene where Yoda does some break dancing. Less well known is the unpublished Episode Zero: The Birth of Death Kleene Star. The story begins with \textbf{C3PO} as a tween droid in school on his home planet of Tatooine, where he's been instructed to determine all of the ways one can combine the numbers \textbf{1}, \textbf{1}, \textbf{3}, and \textbf{8} using traditional \textbf{+}, \textbf{-}, \textbf{*}, \textbf{/}, and \textbf{()} to generate other positive numbers. He's quick to observe that \textbf{8 / 3 / 1 - 1} generates \textbf{1}, \textbf{3 / 8 + 1 + 1} generates \textbf{2}, and that \textbf{(8 / 3 + 1) * 1} generates \textbf{3}. Within seconds, \textbf{C3PO} states that the smallest positive integer that can't be generated is \textbf{29}. But is \textbf{C3PO} correct? Given an \textbf{n} digit string (\textbf{1} ≤ \textbf{n} ≤ \textbf{7}), compute all of the ways that those \textbf{n} digits can be combined using \textbf{+}, \textbf{-}, \textbf{*}, \textbf{/}, and parentheses, and print out the smallest positive integer that can't be generated. For the string "\textbf{12345}", the numbers \textbf{1} through \textbf{75} can be generated, but the number \textbf{76} can't be. For the string "\textbf{13555}", the numbers \textbf{1} through \textbf{55} can be generated, but \textbf{56} can't be. \textbf{Additional Details}: You must use all of the digits, including duplicates. You can't combine digits using concatenation, so that \textbf{12 + 345} would \textbf{*not*} be relevant to the generation of all possibilities on behalf of "\textbf{12345}". Division is integer division, complete with the truncation you expect from integer division. That means that \textbf{4 * (5/4}) is \textbf{4}, not \textbf{5 }(although\textbf{ (4 * 5)/4} is, of course, the \textbf{5} you'd expect.) You must avoid division by zero and disallow it from contributing to the set of generated numbers. The test inputs will be such that all intermediate and final results can fit into a \textbf{32}-bit integer (long). \InputFile Expect a series of digit strings, one per line. End of input will be signaled by a \textbf{0} on its very own line. Do not process this case. \OutputFile You should produce one line of output to standard out for every line of input. Each line of output should be the smallest positive integer that *cannot* be generated by some arithmetic expression involving all of the digits.
Zaman məhdudiyyəti 3 saniyə
Yaddaşı istafadə məhdudiyyəti 256 MiB
Giriş verilənləri #1
1138
12345
13555
167283
123458
4321678
0
Çıxış verilənləri #1
29
76
56
524
347
1774
Mənbə ACM ICPC Regionals 2009: North America - Pacific Northwest