You are given an array and you need to find number of Triplets of indices (i, j, k)such that the elements at those indices are ingeometric progressionfor a given common ratior and i < j < k
For example, arr = [ 1, 4, 16, 64 ]. If r = 4, we have [1, 4, 16]and [4, 16, 64]at indices (0, 1, 2)and ( 1, 2, 3 ).
Function Description
Complete thecountTripletsfunction in the editor below. It should return the number of triplets forming a geometric progression for a givenas an integer.
countTriplets has the following parameter(s):
arr: an array of integers
r: an integer, the common ratio
Input Format
The first line contains two space-separated integers nand r, the size of arrand the common ratio. The next line contains nspace-seperated integers arr[i]
Output Format
Return the count of triplets that form a geometric progression.
Explanation 0
There are2triplets in satisfying our criteria, whose indices are(0,1,2)and(0,2,3)
번역:
당신은 주어진 배열에서 세개의 인덱스 ( i, j, k) 를 찾아야 한다. 그인덱스의요소들은 등비수열이며 공비는 r 이며 i < j < k 이다.
예를 들어arr = [ 1, 4, 16, 64 ] 일때 만약 r = 4 라면, 우리는[1, 4, 16]와 [4, 16, 64] 의 인덱스인(0, 1, 2)와( 1, 2, 3 )을 갖게 된다.
기능 설명
아래의 에디터에서 countTriplets 를 완성 하세요. 주어진 integer 형태에서 등비수열형태의 세개를 리턴하여야 합니다.
countTriplets은 다음과 같은 변수를 갖고있습니다.
arr : integers의 배열
r : integer, 공비
입력 형태
첫번째 라인은공백으로 구분된 두개의 integer는arr의 사이즈와 공비인n, r 이 포함되어있습니다.