Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб. Question by Ibrahim Mesecan.
Sum of Least Common Multiples (LCM)
Question: Assume
that you are given the following functions and they
are working properly (in the library LCM.h).
#include "utils/LCM.h"
void getNums(int
&num1, int &num2);
int GCD(int m,
int n);
where getNums gets two numbers
from an input stream and GCD calculates and returns the
greatest common divisor of two numbers given.
Then, LCM of two numbers can be calculated as follows:
- first calculate the GCD of given numbers
- then, each number is divided by GCD (let's say that
results are stored in res1 and res2)
- Then, LCM is the product of GCD, res1, and res2.
Question:
Write a program that reads n pairs of numbers using
getNums function. Then, the program calculates the
LCM of each pair, and, shows the sum of LCMs in the end.
Input specification
You will be first given the number of number pairs (n)
where n is between 0 and 1000.
Then, get n number pairs (using getNums function).
Each number is between 1 and 100000.
Output specification
Show one integer.
Для отправки решений необходимо выполнить вход.
|