Need help http://codeforces.com/contest/1409/problem/C

Codeforces Round #667 (Div. 3) problem C

problem C Tutorial

#include <bits/stdc++.h>

using namespace std;

int main() {
    int tcs;
    cin >> tcs;

    while (tcs--) {
        int n, x, y;
        cin >> n >> x >> y;
        int diff = y - x;
        for (int delta = 1; delta <= diff; ++delta) {
            if (diff % delta) continue;
            if (diff / delta + 1 > n) continue;
            int k = min((y - 1) / delta, n - 1);
            int a0 = y - k * delta;
            for (int i = 0; i < n; ++i) {
                cout << (a0 + i * delta) << ' ';
            }
            cout << endl;
            break;
        }
    }
}

can any one explain what is concept behind a0 (the first term)

your effort is really appreciated and thanks for help

please help

The give sequence is an Arithmetic Progression with first term as a0.
delta is the difference between two terms.
try all possible difference.

1 Like

thanks for reply
yes diff is difference between two terms but
what is k and how come a0 = y - k * delta [the first term]

    cin>>n>>a>>b;
   if(n==2)
   {
    cout<<a<<" "<<b<<endl;
   } else {
    ll f = b - a , i;
    for(i=1;i<=f;i++)
    {
      if(f%i==0&&i*n>f)
        break;
    }
    ll j;
    for(j=a;j>0;j = j - i)
    {
      
      if(j+i*n<=b)
        break;
    }
    j = j + i;
    for(ll x=0;x<n;x++)
    {
      cout<<x*i + j<<" ";
    }
    cout<<endl;
   }

i Brute forced the whole given number to find the difference of AP and then used the difference to create the array itself ,

1 Like