fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #include <algorithm>
  5. #include <set>
  6. using namespace std;
  7. typedef long long ll;
  8.  
  9. ll gcd(ll a, ll b) {
  10. while (b != 0) {
  11. ll temp = b;
  12. b = a % b;
  13. a = temp;
  14. }
  15. return a;
  16. }
  17.  
  18. int main() {
  19. int t;
  20. cin >> t;
  21. while(t--){
  22. ll l, r, k;
  23. bool b = false;
  24. cin >> l >> r >> k;
  25. l = (l + k - 1) / k;
  26. r = r / k;
  27.  
  28. if(r - l < 0 || r - l == 0 && r != 1){
  29. cout << "-1 -1\n";
  30. }
  31. else{
  32. for(ll i = r - l; i >= 0; i--){
  33. for(ll j = 0; l + j + i <= r; j++){
  34. if(gcd(l + j, l + j + i) == 1){
  35. cout << (l + j) * k << " " << (l + j + i) * k << endl;
  36. b = true;
  37. break;
  38. }
  39. }
  40. if(b)break;
  41. }
  42. }
  43. }
  44. }
Success #stdin #stdout 0s 5292KB
stdin
4
1000 9109235357783 2
4 8 3
4 8 4
5 7 6
stdout
1000 9109235357782
-1 -1
4 8
6 6