#P6068. Maximizing GCD in Tripartition
Maximizing GCD in Tripartition
Maximizing GCD in Tripartition
Relish loves \(\mathrm{gcd}\), i.e. the greatest common divisor. If you are not familiar with it, please refer to the GCD - OI Wiki.
Given a positive integer \(n\), partition it into three pairwise distinct positive integers \(a\), \(b\), and \(c\) such that \(a+b+c=n\) and the value of \(\mathrm{gcd}(a,b,c)\) is maximized. Note that if \(a=d\cdot x\), \(b=d\cdot y\), \(c=d\cdot z\) with \(x,y,z\) being distinct positive integers, then \(d\) divides \(\mathrm{gcd}(a,b,c)\). Therefore, to maximize \(\mathrm{gcd}(a,b,c)\), one may minimize \(x+y+z\). A feasible choice is \((x,y,z)=(1,2,s-3)\) for some integer \(s\ge6\) as \(1+2+(s-3)=s\). Then, if \(s\) divides \(n\), set \(d=n/s\) and obtain \(a=d,\, b=2d,\, c=d\cdot(s-3)\). Your task is to find the smallest \(s\) (\(s\ge6\)) such that \(s\) divides \(n\) and report the corresponding \(a\), \(b\), and \(c\).
inputFormat
A single line containing a positive integer (n) (with (n\ge6)).
outputFormat
Output three space-separated positive integers (a), (b), and (c) such that (a+b+c=n), the three numbers are pairwise distinct, and (\mathrm{gcd}(a,b,c)) is maximized.
sample
6
1 2 3