#K77422. Difference Between Largest and Smallest Prime Factors
Difference Between Largest and Smallest Prime Factors
Difference Between Largest and Smallest Prime Factors
Given an integer \(n\), compute the difference between the largest and smallest prime factors of \(n\). Let \(P\) be the set of distinct prime factors of \(n\). If \(|P| < 2\) (i.e. if \(n\) has fewer than two distinct prime factors), then the answer is 0. Otherwise, the answer is \(\max(P) - \min(P)\).
Examples:
- For \(n = 60\), the prime factors are \(\{2, 3, 5\}\) and the difference is \(5 - 2 = 3\).
- For \(n = 49\), the only prime factor is \(7\), so the answer is 0.
- For \(n = 30\), the prime factors are \(\{2, 3, 5\}\) and the difference is \(5 - 2 = 3\).
inputFormat
The input consists of a single integer (n) (where (1 \leq n \leq 10^9)). The integer is read from standard input.
outputFormat
Output a single integer representing the difference between the largest and smallest prime factors of (n). If (n) has fewer than two distinct prime factors, output 0.## sample
60
3