Search This Blog

Friday, 19 August 2016

SPOJ - AP-Complete The Series Easy Problem Solution

SPOJ - AP-Complete The Series Easy Problem Solution

Solution:-

#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    int tc;
    ll third,last_third,sum;
    int n,first,common_diff;
    cin>>tc;
    while(tc--)
    {
        cin>>third>>last_third>>sum;

        n=(2*sum)/(third+last_third);

        common_diff=(last_third-third)/(n-5);

        first=third-(2*common_diff);
        cout<<n<<"\n";
        for(ll i=0;i<n;i++)
            cout<<first+i*common_diff<<" ";
        cout<<"\n";
    }
    return 0;

}

No comments:

Post a Comment