UVa 10586 - Polynomial Remains Solution

#include <iostream>
#include <vector>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    int n,k;
    while(cin>>n>>k){
        if(n<0)
            return 0;
        if(k>n){
            cin>>k;
            cout<<k;
            while(n--){
                cin>>k;
                cout<<' '<<k;
            }
            cout<<endl;
            continue;
        }
        vector<int> a(n+1);
        for(int i=n;i>=0;i--)
            cin>>a[i];
        for(int i=k;i<=n;i++)
            a[i]-=a[i-k];
        cout<<a[n];
        k--;
        for(int i=n-1;(k--)>0;i--)
            cout<<' '<<a[i];
        cout<<endl;
    }
}

Comments