Блог пользователя Reducto

Автор Reducto, история, 3 года назад, По-английски

Hello, Codeforces community. Can you help me in this question, i am not able to get any intuition about solving this. Here is the question

Given a directed graph of N nodes, each node has a value A[i].

There is a directed edge of length 1 from node i to node j if and only if:

  • | i — j | <= k . The absolute difference between i and j is less than or equal to k.

  • A[i] > A[j]

For each node X, find B[X] which is the length of the shortest path to a node Y such that A[Y] is a prime number. If there is no way to go to such a node Y then we say that B[X] is 0.

Print the sum of all elements in array B.

Since the answer might be large return it modulo 10^9 + 7.

Constraints

1 <= N <= 10^5 and 1 <= k <= N

1 <= A[i] <= 10^6

Input

  • 5 2

  • 2 4 8 16 32

Output

  • 6

Input

  • 3 1

  • 1 2 4

Output

  • 1

Полный текст и комментарии »

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится