#!/usr/bin/env python3
bound = 10**12
nums = set()
nums.add(1)
for base in range(2, int(bound**0.5)+1):
r = base**2 + base + 1
pw = 3
while r < bound:
if r not in nums:
nums.add(r)
r += base**pw
pw += 1
print(sum(nums))