HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Functions > problem:


50527 - Sum of LCMs

Volume problems

• 50917 - Descending Numbers
• 50982 - A thief in labyrinth
• 50980 - The smallest rectangle
• 50932 - Shifting rows and columns
• 50933 - Sum of the Biggest Neighbors
• 50834 - The train which leaves the f...
• 51003 - Double Prime
• 50435 - City Electric Bills
• 50527 - Sum of LCMs
• 50353 - Cube of the Largest number
• 50539 - Number of Chairs - 2
• 50469 - Letter Grades
• 51012 - Palindrome-k
• 50559 - Prime Factors of a Number
• 002. 50428 - Three Times
• 003. 50432 - Numbers and Squares
• 004. 50433 - Sum of Cubes

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
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.

Для отправки решений необходимо выполнить вход.

www.contester.ru