fork(2) download
  1. #include<bits/stdc++.h>
  2. typedef long long ll;
  3. using namespace std;
  4.  
  5. ll gcd(ll a, ll b) {
  6. return !b ? a : gcd(b, a%b);
  7. }
  8.  
  9. bool check(ll x) {
  10. if(x <= 10) return false;
  11. string s1 = "";
  12. while(x) {
  13. s1 += x%10 + '0';
  14. x /= 10;
  15. }
  16. reverse(s1.begin(), s1.end());
  17. int n = s1.length();
  18. string s2 = s1.substr(0, (n+1)/2);
  19. string s3 = s1.substr((n+1)/2);
  20. ll a = 0, b = 0;
  21. for(int i=0; i<s2.length(); ++i)
  22. a = a*10 + s2[i] - '0';
  23. for(int i=0; i<s3.length(); ++i)
  24. b = b*10 + s3[i] - '0';
  25. return gcd(a, b) == 1;
  26. }
  27.  
  28. int main() {
  29. ll a, b, c;
  30. int t; scanf("%d", &t);
  31. while(t--) {
  32. scanf("%lld%lld", &a, &b);
  33. c = -1;
  34. for(ll i=b; i>=a; --i) {
  35. if(check(i)) {
  36. c = i;
  37. break;
  38. }
  39. }
  40. printf("%lld\n", c);
  41. }
  42. return 0;
  43. }
Success #stdin #stdout 0s 4392KB
stdin
2
21 25
110 186
stdout
25
185