SHARE
TWEET

Untitled

a guest Apr 13th, 2011 362 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <set>
  2. #include <algorithm>
  3. #include <cstdio>
  4. using namespace std;
  5. int a, b, l ,r;
  6. set<int, greater<int> > t;
  7. int main()
  8. {
  9.     scanf("%d %d", &a, &b);
  10.     a = __gcd(a, b);
  11.     for (int i = 1; i * i <= a; ++i)
  12.         if (a % i == 0)
  13.         {
  14.             t.insert(i);
  15.             t.insert(a / i);
  16.         }
  17.     scanf("%d", &b);
  18.     while (b--)
  19.     {
  20.         scanf("%d %d", &l, &r);
  21.         a = *lower_bound(t.begin(), t.end(), r, greater<int>());
  22.         printf(a > r || a  < l ? "-1\n" : "%d\n", a);
  23.     }
  24.     return 0;
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top