Advertisement
Saleh127

UVA 326

Jul 23rd, 2021
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10.  
  11. ll n,m,i,j,k,l;
  12.  
  13. while(cin>>n && n)
  14. {
  15. ll a[n+4];
  16.  
  17. for(i=0;i<n;i++) cin>>a[i];
  18.  
  19. cin>>k;
  20.  
  21. for(i=n-1;i>=0;i--)
  22. {
  23. for(j=0;j<i;j++)
  24. {
  25. a[j]=a[j+1]-a[j];
  26. }
  27. }
  28.  
  29. for(i=0;i<k;i++)
  30. {
  31. for(j=1;j<n;j++)
  32. {
  33. a[j]+=a[j-1];
  34. }
  35. }
  36.  
  37. cout<<"Term "<<n+k<<" of the sequence is "<<a[n-1]<<endl;
  38.  
  39. }
  40.  
  41. return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement