L_Wave's blog

By L_Wave, history, 5 weeks ago, In English

Let $$$m$$$ be an arbitrary positive integer. We construct an array $$${a}$$$ where $$$\forall n\in\mathbb{N}_+,\sum_{k\mid n}a_k=m^n$$$. Please prove: $$$\forall n\in\mathbb{N}_+,n\mid a_n$$$.

My first thought is to use Mobius inversion to translate the definition of $$${a}$$$ into $$$a_n=\sum_{k\mid n}m^k\mu(\frac nk)$$$. Then I tried to prove: Let $$$n=p_1^{c_1}p_2^{c^2}\cdots p_k^{c_k}$$$ be the unique factorization of $$$n$$$, for all $$$1\le i\le k$$$ the condition $$$p_i^{c_i}\mid a_n$$$ holds. But I made a little mistake. I forgot the other powers of $$$p_i$$$.

So who can prove this statement? Please comment here, thanks!

Full text and comments »

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

By L_Wave, history, 2 months ago, In English

I solved 1804F recently. It was a cute problem! But what made me curious was how the checker and generator works. It is clear that the $$$d(G)$$$ in the problem cannot be calculated by the checker every time when judging a submission, or the checker would TLE.

So there are extra lines in the input. They must be encoded and used to determine every $$$d(G)$$$. I guess that the checker&generator would work as one of the following two ways:

Method 1

  • Determine every $$$d(G)$$$ in the beginning.
  • Generate a graph satisfying the $$$d(G)$$$ constraint.
  • Encode $$$d(G)$$$ and print them into the input.

Method 2

  • Generate a graph randomly, and use brute force to calculate $$$d(G)$$$. If there is a way in $$$O(qn\text{polylog}n)$$$, it will cost only about $$$500s$$$ for every test case.
  • Encode $$$d(G)$$$ and print them into the input.

For the checker, just read the encoded $$$d(G)$$$ from the input and decode them.

But for either of them I don't know the details (how to generate a graph according to $$$d(G)$$$, how the brute force works, ...). Anyone can explain to me? Maybe I should mention the author GlebsHP.

Full text and comments »

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

By L_Wave, history, 5 months ago, In English

In round 953 (div 2), the user Teddiursa used only five minutes to pass F. Also, his coding styles and default templates were different for problems D, E, F. So I think it’s a multi-people account.

Hope MikeMirzayanov can check this.

Full text and comments »

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

By L_Wave, history, 9 months ago, In English

Hi, CodeForces! I recently found a way to calculate Riordan Array $$$T(n,k)$$$ in $$$\Theta(1)$$$ time. So I'm going to share it with you :D

**Note: ** We define $$$[P]$$$ as the Iverson bracket, with value $$$1$$$ if $$$P$$$ is true and $$$0$$$ if $$$P$$$ is false.

Definition of 'Riordan Array' in this blog

In this blog, Riordan array doesn't have much to do with generating functions. I would choose to define it as A201780 in OEIS, or as the following formula:

$$$ T(n,k)=\begin{cases} 0,&k\le 0;\\ 0,&n<k;\\ 1,&n=k=1;\\ 0,&n=2,k=1;\\ 1,&n=3,k=1;\\ 2T(n-1,k)+T(n-1,k-1),&\text{otherwise}. \end{cases} $$$

It is clear enough that the OEIS page gave only the $$$\Theta(n^2)$$$ method to calculate it, as above shows.

How did I become interested in it?

Recently I solved an interesting problem. In the problem it needs to calculate $$$T(n,k)$$$ in $$$\Theta(1)$$$ time, if we can calculate the binomial coefficient $$$\binom{x}{y}$$$ in $$$\Theta(1)$$$'s time.

problem

I transferred this problem into an easier version: $$$c=0,2\le d\le 3,a\ge 1,b\ge 1$$$. Because it is easy to get the shortest path, so we are going to focus on the number of ways. I solved $$$d=3$$$, but when $$$d=2$$$ it needs to use Riordan Array defined above.

Before starting to solve this, let's focus on an important property.

Property S: the answer of $$$(0,0)c$$$ to $$$(a,b)d$$$ is just the same as the answer of $$$(0,0)c'$$$ to $$$(b,a)d'$$$, where $$$c \oplus c'=d\oplus d'=1$$$. Here $$$\oplus$$$ means xor. You may think of symmetry to proof it.

All the observations down are based on a brute force code's output. So you may write a bfs one as well.

Solving $$$d=3$$$

When $$$a>b$$$, you can observe the output of the bf code, or you can OEIS. When $$$b=5$$$, it's A006975. You can summarize the formulas, and find the answer is:

$$$ \left(3a+b-1,2^{a-b-1}\frac{a+b}{b}\binom{a-1}{b-1}\right) $$$

(I put the length of the shortest path in it, too).

When $$$a=b$$$, the answer is $$$0$$$.

When $$$a<b$$$, the answer is the same as the answer for $$$(b,a)$$$. This is easy to see, too.

Solving $$$d=2$$$ and $$$a\ge b$$$

The answer when $$$d=2$$$ and $$$a<b$$$ can be represented as a formula and has nothing to do with Riordan Array. So I'm going to discard it. When $$$a\ge b$$$, the answer is $$$T(a+2,b+1)$$$. You can use brute force to check it. So, it leads to the calculation of $$$T(x,y)$$$.

I don't know why it has something to do with Riordan arrays, if you know the answer, please comment under this blog or DM me. I will post it as soon as I received the answer.

How to get rid of it?

We can try to move $$$(0,0)0$$$ a little bit. The most optimal way of moving when $$$a\ge b$$$ and $$$d=2$$$ is either move to $$$(0,0),1$$$ using $$$1$$$ edge, or move to $$$(0,1),1$$$ using $$$2$$$ edges, both with only one way to do so. We can first get the shortest path (which is easy), and then use the shorter one to calculate the answer. According to Property S, the answer is among $$$(a',b')=(b,a)$$$ and $$$(a',b')=(b-1,a)$$$.

More formally, we can define an 'add operation' on the answer (length and ways), and a 'multiplying operation'.

$$$ \begin{aligned} &(a,b)(c,d)=(a+c,bd)\\ &(a,b)+(c,d)=\begin{cases} (a,b),&a<b\\ (a,c+d),&a=b\\ (c,d),&a>b \end{cases} \end{aligned} $$$

Then the answer can be showed as $$$S_1(1,1)+S_2(2,1)$$$.

And then I solved the problem. Thus, $$$T(x,y)(0<y\le x,\min(x,y)> 1)$$$ can be calculated as follows:

  1. Solve the problem above with $$$(a,b,c,d)=(x-2,y-1,0,2)$$$.
  2. The number of ways is the answer.

It's perfectly $$$\Theta(1)$$$.

Full code for the original problem

Code

[Update] The generating function way to calculate Riordan Array

Special thanks for MatrixGroup, this part won't appear without him. I copied his comment and made it a bit more beginner-friendly.

Here, $$$T(n,k)$$$ is defined as $$$[n\neq 1\land k=0]$$$ if $$$\min(n,k)=0$$$, and $$$2T(n-1,k)+T(n-1,k-1)$$$ otherwise.

It is easy to check that.

Where the g.f. comes from?
How to get the closed form?

After reading

Chinese editorial for the problem

I would say that it's just magical to connect a math sequence with a CP problem ^=^!

If you have any questions or new ideas, you can comment or DM.

Forgive my poor English please :D

Full text and comments »

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