You are not logged in. Please login at www.codechef.com 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 :- https://www.codechef.com/viewsolution/17434010

asked 13 Feb '18, 23:38

kunal12's gravatar image

3★kunal12
445
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.

link

answered 13 Feb '18, 23:53

akshat98's gravatar image

5★akshat98
112
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. https://comeoncodeon.wordpress.com/2011/05/08/recurrence-relation-and-matrix-exponentiation/

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

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×1,424
×236
×1

question asked: 13 Feb '18, 23:38

question was seen: 231 times

last updated: 14 Feb '18, 00:09