Any optimize idea/hint about this problem?? initially have a idea about calculating trailing 0..... https://open.kattis.com/problems/inversefactorial
Any optimize idea/hint about this problem?? initially have a idea about calculating trailing 0..... https://open.kattis.com/problems/inversefactorial
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3676 |
| 2 | Kevin114514 | 3659 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3382 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3312 |
| 10 | idontwannadothis…e | 3191 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 156 |
| 2 | nik_exists | 151 |
| 3 | maspy | 149 |
| 4 | AmShZ | 145 |
| 5 | Um_nik | 143 |
| 6 | Errichto | 139 |
| 7 | BledDest | 136 |
| 8 | adamant | 135 |
| 9 | maroonrk | 132 |
| 10 | cry | 130 |
| Name |
|---|



There is an editorial on DMOJ: https://dmoj.ca/problem/naq16g.
The title actually got me thinking of this unrelated task. Is it possible?
Can you find the value of $$$n \lt 10^9$$$, given
n! mod (10^9 + 7)as the input? In case of multiple solutions, print any.Finally.. https://ideone.com/vyRFbu
Nice idea! Unfortunately, it is not fully correct as-is. The smallest failing test case is 21008! which happens to coincide with 11448! mod 10^9+7. I expect that doing this with two or three primes of that size simultaneously would be enough to fully solve the problem.
But the problem-setters probably didn't anticipate this approach and prepare counter-tests for popular primes like 10^9+7 or 7*17*2^23+1.
The comment actually got me thinking of this unrelated task. Is it possible?
Can you find the value of $$$n \lt 10^9$$$, given
(b, b^n mod (10^9 + 7))as the input? In case of multiple solutions, print any.Is this simply BSGS Algorithm? It can be solved in $$$\sqrt{mod}$$$ time.
An easy way is the following: find the number of trailing zeros to find the maximum power of 5 that divides this number. Using binary search, you can find the range of 5 integers $$$5n + \varepsilon$$$ with $$$0 \le \varepsilon \lt 5$$$ which are candidates for the inverse factorial of this number. Using divide and conquer and FFT, you can find the factorial of $$$(5n)!$$$ in $$$O(n \log^2 n)$$$ with a not-so-bad constant factor (since you can work in base $$$10^9$$$). Then count the number of digits in it. For every $$$n \gt 1$$$, these five numbers have a different number of digits, and the difference between the number of digits can be estimated easily. For $$$n = 1$$$ you can run a brute force.
$$$\ln x!=x\ln x-x+\frac12\ln\sqrt{2\pi}+\frac12\ln x+o(1)$$$ (the o(1) term is between 0 and 0.1 for all $$$x \gt 1$$$) so it might be possible to binary search for the value of $$$x$$$.