Advertisement
Guest User

Untitled

a guest
Feb 17th, 2021
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define all(x) x.begin(), x.end()
  4. #define revall(x) x.rbegin(), x.rend()
  5. #define OJ \
  6. freopen("input.txt", "r", stdin); \
  7. freopen("output.txt", "w", stdout);
  8. using namespace std;
  9. int mod = 1000000007;
  10. int gcd(ll a, ll b)
  11. {
  12. if (a == 0)
  13. return b;
  14. return gcd(b % a, a);
  15. }
  16.  
  17. void solve()
  18. {
  19. int n;
  20. cin>>n;
  21. int a[n];
  22. for(int i=0;i<n;i++){
  23. cin>>a[i];
  24. }
  25. sort(a,a+n);
  26. set<int> pos;
  27. for(int i=1;i*i<=a[0];i++){
  28. if(a[0]%i==0){
  29. pos.insert(i);
  30. pos.insert(a[0]/i);
  31. }
  32. }
  33. for(int i=1;i*i<=a[0]+1;i++){
  34. if((a[0]+1)%i==0){
  35. pos.insert(i);
  36. pos.insert((a[0]+1)/i);
  37. }
  38. }
  39. for(int i=1;i*i<=(a[0]-1);i++){
  40. if((a[0]-1)%i==0){
  41. pos.insert(i);
  42. pos.insert((a[0]-1)/i);
  43. }
  44. }
  45. int ans=0;
  46. for(auto j:pos){
  47. int cur=j;
  48. // cout<<j<<" ";
  49. for(int i=0;i<n;i++){
  50. if(a[i]%j!=0&&(a[i]-1)%j!=0&&(a[i]+1)%j!=0){
  51. //cout<<a[i]<<" ";
  52. cur=0;
  53. break;
  54. }
  55. }
  56. ans=max(ans,cur);
  57. }
  58.  
  59. cout<<ans<<endl;
  60. }
  61.  
  62. int main()
  63. {
  64. ios_base::sync_with_stdio(false);
  65. cin.tie(NULL);
  66. // OJ;
  67. int T = 1;
  68. cin >> T;
  69. while (T--)
  70. {
  71. solve();
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement