import itertools
target=5000
d=[0]*target
n=2
while n < target:
for i in range(n*n,target,n):
d[i]=d[i]+1
n=n+1
while n < target and d[n]>0:
n=n+1
print sum(2*p*q*r-p*q-p*r-q*r for p,q,r in itertools.combinations([k for k in range(2,target) if d[k]==0],3))