You are not logged in. Please login at to post your questions!


Broken Clock last subtask

How can I reduce the complexity of my code so that last subtask passes. Link to my code :-

asked 13 Feb '18, 23:38

kunal12's gravatar image

accept rate: 0%

The loop which is running for i =2 to t-1 should be removed, and matrix exponentiation can be used, which reduces complexity to O(log t). cos(N∗X)=2∗cos(X)∗cos((N−1)∗X)−cos((N−2)∗X), this can be solved by matrix exponentiation.


answered 13 Feb '18, 23:53

akshat98's gravatar image

accept rate: 0%

edited 14 Feb '18, 00:01

cos(N∗X)=2∗cos(X)∗cos((N−1)∗X)−cos((N−2)∗X). How can I solve this using matrix exponentiation

(14 Feb '18, 00:03) kunal123★

Consider cos(nx) to be F(n). Therefore F(n)=aF(n-1)-F(n-2), (where a=2cos(x)) this is a linear recurrence. Now this can be solved by matrix exponentiation. For matrix exponentiation goto this link.

(14 Feb '18, 00:07) akshat985★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 13 Feb '18, 23:38

question was seen: 231 times

last updated: 14 Feb '18, 00:09