hgtfrdeswa's blog

By hgtfrdeswa, history, 7 weeks ago, In English

Given two operations on a variable $$$a$$$: Replace $$$a$$$ with $$$(a + 1) \mod m$$$, where $$$\%$$$ represents the modulo operation;

Assign $$$a$$$ the value $$$X$$$.

Mr. Tung wants to sequentially generate $$$n$$$ non-negative integers $$$b_1, b_2, \ldots, b_n$$$ starting from the initial value $$$a = b_1$$$, using the above operations and choosing a suitable value $$$X$$$ to minimize the number of operations needed.

Find the minimum number of operations required to obtain the given sequence $$$b$$$.

The first line contains two integers $$$n$$$ and $$$m$$$ $$$(2 \leq n, m \leq 10^5)$$$;

The second line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ $$$(0 \leq b_i < m; 1 \leq i \leq n)$$$.

A single integer, which is the result of the problem.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By hgtfrdeswa, history, 3 months ago, In English

Given a sequence of integers $$$( a_1, a_2, \dots, a_n )$$$ where $$$( 1 \leq a_i \leq 10^6 )$$$, count the number of subsequences with indices $$$( i_1, i_2, \dots, i_k )$$$ such that:

$$$ k > 0 $$$,

$$$ 1 < i_2 < \dots < i_k \leq n ,$$$

$$$ a_{i_1} \leq a_{i_2} \leq \dots \leq a_{i_k} ,$$$

$$$ \gcd(a_{i_1}, a_{i_2}, \dots, a_{i_k}) = 1 .$$$

The first line contains an integer $$$n $$$ $$$(1 \leq n \leq 3 \times 10^5)$$$, representing the number of elements in the sequence.

The second line contains $$$ n $$$ integers $$$ a_1, a_2, \dots, a_n $$$ $$$(1 \leq a_i \leq 10^6)$$$.

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it