// Run time: 0.120
#include <stdio.h>
#define N 500000
int arr[N];
void calculate(int x, int num);
int main()
{
int i;
int num;
int x;
while (scanf("%d", &x) != EOF)
{
for ( i = 0; ; i++)
{
scanf("%d", &arr[i]);
if (getchar() == '\n')
break;
}
num = i; // <=
if (x)
calculate(x, num);
else
printf("%d\n", arr[num-1]);
}
return 0;
}
void calculate(int x, int num)
{
int i, j;
long long int sum = 0;
long long int product = 1;
for ( i = num-1, j = 1; i >= 0; i--, j++)
{
sum += arr[i]*product*j;
product *= x;
}
printf("%lld\n", sum);
}
沒有留言:
張貼留言