#219. 数组递归查找倍数
数组递归查找倍数
Array Multiple Search
Background
This is an exercise problem about recursion and array traversal.
Problem Description
Given an array of integers, compute recursively if the array contains somewhere a value followed in the array by that value times . We'll use the convention of considering only the part of the array that begins at the given index. In this way, a recursive call can pass to move down the array. The initial call will pass in as .
Input Format
Input is given from standard input in the following format.
A single line containing an integer array (enclosed in square brackets, elements separated by spaces) and an integer .
Output Format
Output to standard output in the following format.
Output
trueif such a value exists; otherwise, outputfalse.
Sample
[1 2 20] 0
true
[3 30] 0
true
[3] 0
false
Sample Explanation
Sample 1: For array [1, 2, 20] and starting index .
- When , `arr[0] = 1$. There is no after in the array.
- When ,
arr[1] = 2$. There is $10 \times 2 = 20$ after $2$ in the array (i.e.,arr[2]). Thus,true` is returned.
Sample 2: For array [3, 30] and starting index .
- When ,
arr[0] = 3$. There is $10 \times 3 = 30$ after $3$ in the array (i.e.,arr[1]). Thus,true` is returned.
Sample 3: For array [3] and starting index .
- When ,
arr[0] = 3$. There is no $10 \times 3 = 30$ after $3$ in the array. The array ends, thusfalse` is returned.
Constraints
Time limit for each test case is second, and memory limit is KiB.