P381
projecteuler.net

$(\text{prime}-k)$ Factorial

ℹ️Published on Saturday, 21st April 2012, 05:00 pm; Solved by 4770;
Difficulty rating: 15%

For a prime $p$ let $S(p) = (\sum (p-k)!) \bmod (p)$ for $1 \le k \le 5$.

For example, if $p=7$,
$(7-1)! + (7-2)! + (7-3)! + (7-4)! + (7-5)! = 6! + 5! + 4! + 3! + 2! = 720+120+24+6+2 = 872$.
As $872 \bmod (7) = 4$, $S(7) = 4$.

It can be verified that $\sum S(p) = 480$ for $5 \le p \lt 100$.

Find $\sum S(p)$ for $5 \le p \lt 10^8$.



Soluzione

Last modified: May 01, 2025. Website built with Franklin.jl and the lovely Julia programming language.