1826B - Lunatic Never Content - CodeForces Solution


math number theory

Please click on ads to support us..

C++ Code:

/*
 VINAY SAGAR
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define v vector<int> 
#define en endl
#define l1 1e6
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define sz(a) (int)a.size()
#define loop(ii, n) for (int ii = 0; ii < n; ii++)

const int MOD = 1e9 + 8;
const int N = 1e5+10;

void solve()
{
    int n; cin>>n;

    vector<int> v1;
    loop(i,n)
    {
        int x; cin>>x;
        v1.pb(x);
    }
    

    // int t = abs(v1[n-1]-v1[0]);
    int g = 0;

    loop(i,n/2)
    {
        
       g = __gcd(g,abs(v1[n-i-1]-v1[i]));
    
    }

    cout<<g<<endl;

    

}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        solve();

    }
}


Comments

Submit
0 Comments
More Questions

855B - Marvolo Gaunt's Ring
1454A - Special Permutation
1359A - Berland Poker
459A - Pashmak and Garden
1327B - Princesses and Princes
1450F - The Struggling Contestant
1399B - Gifts Fixing
1138A - Sushi for Two
982C - Cut 'em all
931A - Friends Meeting
1594A - Consecutive Sum Riddle
1466A - Bovine Dilemma
454A - Little Pony and Crystal Mine
2A - Winner
1622B - Berland Music
1139B - Chocolates
1371A - Magical Sticks
1253A - Single Push
706B - Interesting drink
1265A - Beautiful String
214A - System of Equations
287A - IQ Test
1108A - Two distinct points
1064A - Make a triangle
1245C - Constanze's Machine
1005A - Tanya and Stairways
1663F - In Every Generation
1108B - Divisors of Two Integers
1175A - From Hero to Zero
1141A - Game 23