## 11170 - Cos(NA)

**Moderator:** Board moderators

### Re: what was ur approach??

This formula also can solve the probem, the difference is this one doesn't use previous solutions. However, this is much slower.sohel wrote:During the real time contest, I tried this approach:

1] cos(mx) = cos(m/2x + m/2x) =cos^2(m/2x)-sin^2(m/2x)->for even m

sin^2(nx) = 1 - cos^2(nx).

So for even m, I could eliminate sin(). But for odd values of m, I couldn't get rid of sin(). After opening my A'Level Pure Maths book and a bit of googling, I found that cos(nx) can be expressed in terms of cos(n-1) and cos(n-2).

How did you guys do it?

cos(NA)=Re exp(iNA)=Re exp(iA)^N=Re (cos(A)+i*sin(A))^N

Then I use Newton's Binomial to calculate Re (cos(A)+i*sin(A))^N, by taking only even powers.

Best regards

Narek Saribekyan

cos(a+b) = cos(a)cos(b) - sin(a)sin(b)

cos(a-b) = cos(a)cos(b) + sin(a)sin(b)

so cos(a+b)+cos(a-b) = 2 cos(a)cos(b).

Now let a = (N-1)A, b = A, and you get the formula

cos(NA) = 2cos((N-1)A) * cos(A) - cos((N-2)A) and it is clear that cos(NA) is a polynomial of degree N in cos(A).

That is an excellent method, simple yet to the point!sclo wrote:Here's one more way:

cos(a+b) = cos(a)cos(b) - sin(a)sin(b)

cos(a-b) = cos(a)cos(b) + sin(a)sin(b)

so cos(a+b)+cos(a-b) = 2 cos(a)cos(b).

Now let a = (N-1)A, b = A, and you get the formula

cos(NA) = 2cos((N-1)A) * cos(A) - cos((N-2)A) and it is clear that cos(NA) is a polynomial of degree N in cos(A).

Thanks for posting!

So the abs(long long) doesn't work on UVa? That's really weird! I've used it for other problems but for this one I had to hand make abs or I get WA. I guess I was just lucky in all my previous problems.......little joey wrote:I replaced llabs() with a handmade function and got your code accepted, ....

### Re: 11170 - Cos(NA)

how to calculate the coefficient of Chebyshev???