| Winter Cup 4.0 Online Mirror Contest |
|---|
| Закончено |
This is the hard version of the problem. The difference between the two versions are the constraints.
Rami has been always fond of random numbers, he keeps wondering about how randomness arises from the deterministic nature of mathematics.
Wanting to impress his friends, he created a new pseudo-random number generation scheme, that he proudly called Rami Scheme.
A Rami Scheme is used to generate $$$s$$$ random numbers, it consists of the following steps:
1. choose $$$3$$$ integer parameters: $$$p,a,b$$$ such that $$$0\leq a,b, \lt p$$$ with $$$p$$$ prime
2. choose $$$2$$$ seeds $$$u_0,u_1$$$
3. for $$$k \gt 1,$$$ $$$u_k$$$ will be generated with the following rule: $$$$$$ \boxed{u_k=(au_{k-1}+bu_{k-2})\bmod p} $$$$$$
4. using the rule above, he will calculate many such numbers and use them to generate the following random numbers $$$(w_k)_{k\in\mathbb{N}}$$$: $$$$$$ \boxed{w_k=\left(\sum_{i=0}^kiu_i\right)\bmod p} $$$$$$
5. Finally, he will choose $$$s$$$ numbers $$$w_{n_1},\dots,w_{n_s}.$$$ those final numbers will be his sought random numbers.
Rami wants you to evaluate his scheme:
- First of all, he wants you to measure the robustness index $$$R$$$ of this scheme, which is defined as the eventual fundamental period of the sequence $$$(w_k)_{k\in\mathbb{N}}.$$$ In other words,he wants the smallest strictly positive integer $$$R$$$ such that:
$$$$$$ \boxed{\exists K\in\mathbb{N}/\quad\forall k\in\mathbb{N}_{\ge K}, w_{k+R}=w_k} $$$$$$
- After that, he knows that he cannot calculate all terms of the sequence $$$(w_k)_{k\in\mathbb{N}}$$$, and he only needs $$$s$$$ terms $$$w_{n_1},\dots,w_{n_s}$$$ of it. So he asks your help for it.
As the number $$$R$$$ may be too big, Rami will be happy if you only give him $$$R\bmod 2^{64}.$$$
7 2 6 0 1 14 0 1 2 3 4 5 6 7 8 9 10 11 12 13
7 0 1 5 0 2 6 0 0 1 5 0 2 6 0
499 13 41 0 15 5 0 1 2 3 4
31062750 0 15 405 374 47
17 0 0 2 3 7 0 1 2 3 4 5 6
1 0 3 3 3 3 3 3
5 0 0 4 0 8 0 1 2 3 4 5 6 7
1 0 0 0 0 0 0 0 0
975151579 1 1 0 1 5 0 1 2 3 4
950920601051041662 0 1 3 9 21
| Название |
|---|


