eolymp
bolt
Try our new interface for solving problems
Problems

Admission to Exam

Admission to Exam

At the end of the previous semester the students of the Department of Mathematics and Mechanics of the Yekaterinozavodsk State University had to take an exam in network technologies. \textbf{N} professors discussed the curriculum and decided that there would be exactly N2 labs, the first professor would hold labs with numbers \textbf{1}, \textbf{N+1}, \textbf{2N+1}, …, \textbf{N^2−N+1}, the second one --- labs with numbers \textbf{2}, \textbf{N+2}, \textbf{2N+2}, …, \textbf{N^2−N+2}, etc. \textbf{N}-th professor would hold labs with numbers \textbf{N}, \textbf{2N}, \textbf{3N}, …, \textbf{N^2}. The professors remembered that during the last years lazy students didn't attend labs and as a result got bad marks at the exam. So they decided that a student would be admitted to the exam only if he would attend at least one lab of each professor. N roommates didn't know the number of labs and professors in this semester. These students had different diligence: the first student attended all labs, the second one --- only labs which numbers were a multiple of two, the third one --- only labs which numbers were a multiple of three, etc… At the end of the semester it turned out that only \textbf{K} of these students were admitted to the exam. Find the minimal \textbf{N} which makes that possible. \InputFile An integer \textbf{K} (\textbf{1} ≤ \textbf{K} ≤ \textbf{2·10^9}). \OutputFile Output the minimal possible \textbf{N} which satisfies the problem statement. If there is no \textbf{N} for which exactly \textbf{K} students would be admitted to the exam, output \textbf{0}.
Time limit 2 seconds
Memory limit 64 MiB
Input example #1
8
Output example #1
15
Author Igor Chevdar
Source Ural SU Contest. Petrozavodsk Summer Session, August 2008