#B4077. Sports Event Applause Count
Sports Event Applause Count
Sports Event Applause Count
During a sports event, two classes cheer for their athletes on the field. Class A claps every \(x\) seconds and Class B claps every \(y\) seconds. Each clap lasts exactly 1 second. If the event lasts for \(n\) seconds, determine the total number of seconds in which there is applause.
Note: If both classes clap during the same second, that second is counted only once.
The mathematical formula to compute the answer is:
\[ \text{Total Seconds} = \left\lfloor \frac{n}{x} \right\rfloor + \left\lfloor \frac{n}{y} \right\rfloor - \left\lfloor \frac{n}{\mathrm{lcm}(x,y)} \right\rfloor. \]For example, when \(x=2\), \(y=3\), and \(n=10\):
- Class A claps at seconds: 2, 4, 6, 8, 10.
- Class B claps at seconds: 3, 6, 9.
The union of these seconds is \({2,3,4,6,8,9,10}\), so the answer is 7.
inputFormat
The input consists of three positive integers \(x\), \(y\), and \(n\) separated by spaces, where:
- \(x\) is the interval (in seconds) at which Class A claps.
- \(y\) is the interval (in seconds) at which Class B claps.
- \(n\) is the total duration of the event in seconds.
outputFormat
Output a single integer which represents the total number of seconds in which there was applause.
sample
2 3 10
7