#include <bits/stdc++.h>
using namespace std;
const unsigned int MAX = 0xFFFFFFFF;
unsigned int n, a, b, c, d;
bool prime[18000];
vector<unsigned int> ps;
inline unsigned int fun(unsigned int x) {
  return ((a * x + b) * x + c) * x + d;
}
int main() {
  scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
  unsigned int lim = min(n, 17777u);
  fill(prime, prime + lim + 1, true);
  for (unsigned int i = 2; i <= lim; i++) {
    if (prime[i]) {
      ps.push_back(i);
      for (unsigned int j = i * i; j <= lim; j += i) prime[j] = false;
    }
  }
  unsigned int ans = 0;
  for (unsigned int p : ps) {
    unsigned int pw = p, f = fun(p);
    ans += n / pw * f;
    while (MAX / pw >= p && pw * p <= n) {
      pw *= p;
      ans += n / pw * f;
    }
  }
  for (unsigned int blk = 1; blk < (n - 1) / lim + 1; blk++) {
    unsigned int offset = blk * lim;
    fill(prime, prime + lim + 1, true);
    for (unsigned int p : ps)
      for (unsigned int i = (blk * lim / p + 1) * p; i <= (blk + 1) * lim;
           i += p)
        prime[i - offset] = false;
    for (unsigned int i = blk * lim + 1; i <= (blk + 1) * lim; i++)
      if (prime[i - offset]) ans += n / i * fun(i);
  }
  printf("%u\n", ans);
}
