#include <bits/stdc++.h>
using namespace std;
unsigned int A, B, C, D, ans = 0;
long long n;
bitset<100000002> v;
unsigned int f(unsigned int x) { return x * (x * (A * x + B) + C) + D; }
void work(unsigned int x) {
  unsigned int cnt = 0;
  unsigned int t = f(x);
  for (unsigned int i = (x << 1); i <= n; i += x) {
    if (i % 6 == 1) v[(i / 6) << 1] = 1;
    if (i % 6 == 5) v[((i / 6 + 1) << 1) - 1] = 1;
  }
  for (long long i = x; i <= n; i *= x) {
    ans += (n / i) * t, cnt += (n / i);
  }
}
int main() {
  scanf("%lld%u%u%u%u", &n, &A, &B, &C, &D);
  work(2);
  work(3);
  for (unsigned int i = 6; i <= n + 1; i += 6) {
    if (!v[((i / 6) << 1) - 1]) work(i - 1);
    if (i != n && !v[(i / 6) << 1]) work(i + 1);
  }
  printf("%u", ans);
}
