Skip to main content

Posts

Showing posts with the label topcoder

Topcoder SRM 684 DivFreed2 Div 2 level 2

Hello all, today I want to share a problem which comes in many forms of counting the number of sequences subject to some constraints on the elements of the sequence. The problem goes like following. link to problem statement ------------------------------------------------------------------- Problem Statement Hero likes some arrays. The arrays he likes are the arrays that have all of the following properties: The length of the array is n . Each element is an integer between 1 and k , inclusive. Whenever A and B are two consecutive elements of the array (in this order), we have (A <= B) or (A mod B != 0). For example, suppose n =4 and k =7. Hero will like the array {1,7,7,2} because it has the right length, all elements are in the correct range, 1 <= 7, 7 <= 7, and 7 mod 2 != 0. Hero will not like the array {4,4,4,2}. You are given the ints n and k . Let X be the number of different arrays Hero likes. Compute and return the value (X mo