← RoseCode

ROSECODE 553

Primorial

liuguangxi · Math ·

For a positive integer n, the primorial n# is defined as the product of all primes n: 2#=2,3#=6,6#=30,.

Define F(n,p)={n#modp, if n<p,1p×(n#)modp, if np.

For example, F(3,7)=2×3mod7=6 and F(7,3)=2×5×7mod3=1.

For P=998244353, You are given F(143,P)=675572163 and F(109,P)=574463500.

Find F(1013,P).

(My timing: ~20s for 1013, ~65s for 1014)