LightOJ 1215 Finding LCM(数论)
题意 已知LCM(a, b, c) = L 和 a、b、L 求最小的满足等式的c.
把数展开为素因子积的形式后
GCD(a,b)就是a,b的公共素因子取在a、b中的较小指数
LCM(a,b)就是a,b的所有素因子取在a、b中的较大指数
令m = LCM(a,b) 那么问题转化为了求最小的c满足 LCM(m, c) = L
那么最小的c就是L中不在m中的素因子和L中指数大于m中指数的素因子取在L中的指数即积
1 | #include <bits/stdc++.h> |
1215 - Finding LCM
LCM is an abbreviation used for Least Common Multiple in Mathematics. We say LCM (a, b, c) = L if and only if L is the least integer which is divisible by a, band c.
You will be given a, b and L. You have to find c such that LCM (a, b, c) = L. If there are several solutions, print the one where c is as small as possible. If there is no solution, report so.
Input
Input starts with an integer T (≤ 325), denoting the number of test cases.
Each case starts with a line containing three integers a b L (1 ≤ a, b ≤ 106, 1 ≤ L ≤ 1012).
Output
For each case, print the case number and the minimum possible value of c. If no solution is found, print ‘impossible’.
Sample Input
Output for Sample Input 3
3 5 30
209475 6992 77086800
2 6 10
Case 1: 2
Case 2: 1
Case 3: impossible