1. 程式人生 > >Finding LCM LightOJ - 1215 (水題)

Finding LCM LightOJ - 1215 (水題)

out printf n) tac vector tps cin cnblogs queue

這題和這題一樣。。。。。。只不過多了個數。。。

Finding LCM

LightOJ - 1215

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; }

Finding LCM LightOJ - 1215 (水題)