Submit | All submissions | Best solutions | Back to list |
GSMATRIX - Matrix |
Mr. Ganesh, a friend of Mr. Dengklek, give Mr. Dengklek a big matrix A dan asking the result of AN. Because the matrix A is too big and Mr Dengklek doesn't have a lot of time, he wants to minimize the number of multiplication needed for computing AN. In this case, assume Mr. Dengklek always stores the matrices that Mr. Dengklek ever computed, thus, if anytime Mr. Dengklek wants to use that matrix again, he can just directly use it without recomputing it.
You must help Mr. Dengklek to find out the minimum number of multiplication required to compute AN.
Input
The first line consist of a single integer N (1 ≤ N ≤ 120).
Output
In the first line, output the result asked in the problem statement above.
Example Explanation
Here is one of the possible minimum calculation to get A15.
Matrices that Mr. Dengklek have : A
1st multiplication : A × A = A2
Matrices that Mr. Dengklek have : A, A2
2nd multiplication : A × A2 = A3
Matrices that Mr. Dengklek have : A, A2, A3
3rd multiplication : A3 × A3 = A6
Matrices that Mr. Dengklek have : A, A2, A3, A6
4th multiplication : A6 × A6 = A12
Matrices that Mr. Dengklek have : A, A2, A3, A6, A12
5th multiplication : A12 × A3 = A15
Example
Input: 15 Output: 5
Added by: | jonathanirvings |
Date: | 2015-12-22 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 GOSU JS-MONKEY |
Resource: | ITBPC 2010 |
hide comments
2019-01-02 19:28:44
How do I solve this without using brute-force? |
|
2018-10-20 13:35:24 :D
Also check similar but harder problem YOKOF |
|
2018-04-30 13:13:01
@DIWAKAR BHARDWAJ,but note that each operation just A*B(two);A*B*C(more than two) is invalid. |
|
2017-07-10 14:28:19
A big deal :) |
|
2017-01-26 07:42:05
Can someone please email their code for this question to me. I've already solved this question but I'm not happy with the way I've solved it. Id-(ksuhas19@gmail.com) |
|
2016-05-06 22:18:24 candide
Interesting question but input range is too narrow. One line of code in Python. @Mohamed Badawy: 77 -> 8 Last edit: 2016-05-06 22:31:08 |
|
2016-01-05 21:48:17 Mohamed Badawy
please add more tricky test cases my solution got accepted while it answered wrong to n=77 |
|
2015-12-24 14:30:26 shally darbari
why it is giving wrong answer??any tricky test case?? |
|
2015-12-23 11:02:49 DIWAKAR BHARDWAJ
I think ans should be 4 |