这题和这题一样。。。。。。只不过多了个数。。。
Finding LCM
https://www.cnblogs.com/WTSRUVF/p/9316412.html
#include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <set> #include <vector> #include <stack> #include <queue> #include <algorithm> #include <cmath> #define rap(a, n) for(int i=1; i<=n; i++) #define MOD 2018 #define LL long long #define ULL unsigned long long #define Pair pair<int, int> #define mem(a, b) memset(a, b, sizeof(a)) #define _ ios_base::sync_with_stdio(0),cin.tie(0) //freopen("1.txt", "r", stdin); using namespace std; const int maxn = 10010, INF = 0x7fffffff; LL gcd(LL a, LL b) { return b==0?a:gcd(b, a%b); } int main() { int T, kase = 0; cin>> T; while(T--) { LL a, b, L; cin>> a >> b >> L; printf("Case %d: ", ++kase); LL c = a * b / gcd(a, b); if(L % c) { cout<< "impossible" <<endl; continue; } LL d = L / c; while(gcd(c, d) != 1) { LL m = gcd(c, d); c /= m; d *= m; } cout<< d <<endl; } return 0; }