Advertisement
haufont

Untitled

Jul 23rd, 2016
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include<algorithm>
  2. #include<set>
  3. #include<vector>
  4. #include<string>
  5. #include<stdlib.h>
  6. #include<math.h>
  7. #include<stdio.h>
  8. #include<map>
  9. #include<iostream>
  10. using namespace std;
  11. set<long long> s;
  12. int main()
  13. {
  14. long long a, b;
  15. cin >> a >> b;
  16. long long x = max(a, b);
  17. long long y = min(a, b);
  18. for (long long i = 1; i*i <= x; i++)
  19. {
  20. if ((x%i == 0)&&(y%i==0))
  21. {
  22. s.insert(i);
  23. }
  24. if ((y % (x / i) == 0)&&(x%i==0))
  25. {
  26. s.insert(x / i);
  27. }
  28. }
  29. long long jmin, jmax;
  30. long long e = -1;
  31. long long k;
  32. cin >> k;
  33. for (int i = 0; i < k; i++)
  34. {
  35. cin >> jmin >> jmax;
  36. auto it = s.end();
  37. it--;
  38. while (*it > jmax)
  39. {
  40. it--;
  41. }
  42. if ((*it >= jmin) && (*it <= jmax))
  43. {
  44. e = *it;
  45. }
  46. cout << e << endl;
  47. e = -1;
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement