Solution for 423 (runs in 1 min).
A little bit of brute-force and a little bit of inclusion-exclusion for 322 (runs in 10 mins but could clearly be optimized further.
DP based solutions for 416 using fast exponentiation (runs in 35mins in python, 10s using numpy).
Far too complex solution for 402 (runs in 15 mins).