Compile Error
foo.cc: In function 'void solve()': foo.cc:10:20: error: 'lcm' was not declared in this scope 10 | int l = lcm(a, lcm(b, c)); | ^~~ foo.cc:10:13: error: 'lcm' was not declared in this scope 10 | int l = lcm(a, lcm(b, c)); | ^~~
Code
#include <iostream>
#include <algorithm>
using namespace std;
void solve() {
int a, b, c, x;
cin >> a >> b >> c >> x;
// Calculate the least common multiple (LCM) of a, b, and c
int l = lcm(a, lcm(b, c));
// If LCM is greater than or equal to X, no valid multiple exists
if (l >= x) {
cout << -1 << endl;
return;
}
// Find the greatest multiple of `l` that is strictly less than `X`
int k = (x - 1) / l;
int ans = k * l;
cout << ans << endl;
}
int main() {
int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1025 GCM
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2024-10-07 19:34:47
- Judged At
- 2024-11-11 02:38:55
- Judged By
- Score
- 0
- Total Time
- 0ms
- Peak Memory
- 0 Bytes