def fact(n, memo={}):
if n == 0: return 1
if n not in memo:
memo[n] = n * fact(n-1, memo)
return memo[n]
def is_prime(n):
return fact(n-1) % n == n-1
print(sum(x for x in range(1,10001) if not is_prime(x)))
ZGVmIGZhY3QobiwgbWVtbz17fSk6CiAgICBpZiBuID09IDA6IHJldHVybiAxCiAgICBpZiBuIG5vdCBpbiBtZW1vOgogICAgICAgIG1lbW9bbl0gPSBuICogZmFjdChuLTEsIG1lbW8pCiAgICByZXR1cm4gbWVtb1tuXQoKZGVmIGlzX3ByaW1lKG4pOgogICAgcmV0dXJuIGZhY3Qobi0xKSAlIG4gPT0gbi0xCgpwcmludChzdW0oeCBmb3IgeCBpbiByYW5nZSgxLDEwMDAxKSBpZiBub3QgaXNfcHJpbWUoeCkpKQ==