Advertisement
Pabon_SEC

Integer Sequences from Addition of Terms

May 18th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int arr[25];
  6.  
  7. int main()
  8. {
  9.     int test,i,j,n,d,k,sum,a;
  10.  
  11.     long long total;
  12.  
  13.     scanf("%d",&test);
  14.  
  15.     while(test--)
  16.     {
  17.         scanf("%d",&n);
  18.  
  19.         for(i=1; i<=n+1; i++)
  20.         {
  21.             scanf("%d",&arr[i]);
  22.         }
  23.  
  24.         scanf("%d%d",&d,&k);
  25.  
  26.         total = sum = 0;
  27.  
  28.         a = d;
  29.  
  30.         for(i=1 ; ; i++)
  31.         {
  32.             sum+=a;
  33.  
  34.             if(sum>=k)
  35.                 break;
  36.  
  37.             a = d*(i+1);
  38.         }
  39.  
  40.         total = arr[1];
  41.  
  42.         for(j=2;j<=n+1;j++)
  43.         {
  44.             total+= arr[j]*(pow(i,j-1));
  45.         }
  46.  
  47.         printf("%lld\n",total);
  48.     }
  49.  
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement