← RoseCode

ROSECODE 416

Fifty-Fifty

Min_25 · Math ·

Let p4,3(n) be the smallest prime p such that p>n and p3(mod4) and let p4,3k(n):={p4,3k1(p4,3(n))if k>1p4,3(n)if k=1.

Let F(n):=n12!modn.

For example, F(3)=1 and F(47)=46.

Let S(n,m):=k=1mF(p4,3k(n)).

You are given S(1,32)=1856, S(107,32)=150008239 and S(1012,32)=18000000012930.

Find S(1018,32).

[My timing: 1.8 seconds (PyPy)]

Note: It would be hard without parigp.