fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(NULL);
  7.  
  8. int t;
  9. cin >> t;
  10. while (t--) {
  11. long long l, a, b;
  12. cin >> l >> a >> b;
  13. long long g = __gcd(l, b);
  14. long long ans = a + ((l - 1 - a) / g) * g;
  15. cout << ans << '\n';
  16. }
  17. return 0;
  18. }
  19.  
Success #stdin #stdout 0s 5324KB
stdin
4
5 3 2
2 0 6
8 2 4
100 0 1
stdout
4
0
6
99