Sum of sines#11442

Sum of sines (Editorial)

Compute the specified sum using a loop.

At the -th iteration, store the value sin^ix in the variable . At the -th iteration, add the current term t = sin^ix to the current value of the result .

Algorithm implementation

Read the input data.

scanf("%d %lf", &n, &x);

Compute the value of the sum using a loop.

res = 0; t = 1;
for (i = 0; i < n; i++)
{

At the -th iteration, it is necessary to multiply by , and then add the current term t = sin^ix to the result .

  t = t * sin(x);
  res = res + t;
}

Print the answer.

printf("%lf\n", res);

Python implementation

import math

Read the input data.

n, x = input().split()
n = int(n)
x = float(x)

Compute the value of the sum using a loop.

res, t = 0, 1
for i in range(n):

At the -th iteration, it is necessary to multiply by , and then add the current term t = sin^ix to the result .

  t *= math.sin(x)
  res += t

Print the answer.

print(res)