#include <bits/stdc++.h>
using namespace std;
namespace sieve {
const int MAXN = 33000;
bool pr[MAXN];
int divisor[MAXN];
int P[MAXN];
void run(int n) {
  memset(pr, 1, sizeof(pr));
  pr[0] = pr[1] = false;
  for (int i = 2; i * i <= n; ++i) {
    if (!pr[i]) continue;
    int k = i * i;
    while (k <= n) {
      pr[k] = false;
      k += i;
    }
  }
}
inline int get_div(int n) {
  if (pr[n]) return n;
  return divisor[n];
}
int factorize(int v[], int n) {
  if (n <= 1) return 0;
  int sz = 0;
  while (n > 1) {
    int p = get_div(n);
    v[sz++] = p;
    n /= p;
  }
  return sz;
}
void run_segmented(int n, function<void(int)> f) {
  int sqrtn = sqrt(n);
  run(sqrtn);
  int sz = 0;
  for (int i = 0; i < (sqrtn + 1); ++i)
    if (pr[i]) P[sz++] = i;
  int a = 2;
  while (a <= n) {
    int b = min(a + 32768 - 1, n);
    memset(pr, 1, sizeof(pr));
    for (int i = 0; i < (sz); ++i) {
      int p = P[i], p2 = p * p;
      if (p2 > b) break;
      int k = max(a / p * p, p2);
      if (k < a) k += p;
      while (k <= b) {
        pr[k - a] = false;
        k += p;
      }
    }
    for (int i = a; i < (b + 1); ++i)
      if (pr[i - a]) f(i);
    a = b + 1;
  }
}
}  // namespace sieve
const long long MOD = (1LL << 32);
long long A, B, C, D;
unsigned int add(unsigned int a, unsigned int b) {
  return ((long long)(a) + b) % MOD;
}
unsigned int mul(unsigned int a, unsigned int b) {
  return (unsigned long long)(a)*b % MOD;
}
unsigned int f(unsigned int x) {
  unsigned int ans = D;
  unsigned int base = x;
  ans = add(ans, mul(C, x));
  x = mul(x, base);
  ans = add(ans, mul(B, x));
  x = mul(x, base);
  ans = add(ans, mul(A, x));
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  ios::sync_with_stdio(false);
  int n;
  cin >> n >> A >> B >> C >> D;
  unsigned int ans = 0;
  sieve::run_segmented(n, [&ans, n](int i) {
    long long p = i;
    int qty = 0;
    while (p <= n) {
      qty += n / p;
      p *= i;
    }
    ans = add(ans, mul(qty, f(i)));
  });
  cout << ans << endl;
  return 0;
}
