#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T& x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}
template <typename T, typename... U>
inline void read(T& x, U&... y) {
  read(x), read(y...);
}
const long long P = 1ll << 32;
int n, A, B, C, D;
bitset<100000010> G;
long long F(int x) {
  return (1ll * A * x % P * x % P * x % P + 1ll * B * x % P * x % P +
          1ll * C * x % P + D) %
         P;
}
int main() {
  read(n, A, B, C, D);
  long long res = 0, V;
  V = F(2);
  for (int i = 2; i <= n; i += 2) {
    int x = i;
    while (x % 2 == 0) {
      res += V;
      if (res >= P) res -= P;
      x /= 2;
    }
  }
  V = F(3);
  for (int i = 3; i <= n; i += 3) {
    int x = i;
    while (x % 3 == 0) {
      res += V;
      if (res >= P) res -= P;
      x /= 3;
    }
  }
  for (int i = 4; i <= n; ++i)
    if (i % 2 && i % 3) {
      if (G.test(i - i / 2 - i / 3 + i / 6)) continue;
      for (int j = i; j <= n; j += i)
        if (j % 2 && j % 3) G.set(j - j / 2 - j / 3 + j / 6);
      int x = n, g = 0;
      while (x) g += x / i, x /= i;
      res += 1ll * g * F(i) % P;
      if (res >= P) res -= P;
    }
  printf("%lld\n", res);
  return 0;
}
