#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - 48;
    ch = getchar();
  }
  return x * f;
}
template <typename T>
inline void Max(T &a, T b) {
  if (a < b) a = b;
}
template <typename T>
inline void Min(T &a, T b) {
  if (a > b) a = b;
}
const int N = 1e8 + 7;
int pc;
bitset<N> vis;
int n;
unsigned int A, B, C, D, ans;
int getp(int j) { return j / 6 * 2 + (j % 6 == 1 ? 1 : 2); }
int main() {
  n = gi(), A = gi(), B = gi(), C = gi(), D = gi();
  for (int i = 2; i <= n; ++i) {
    if (i > 3 && (i % 2 == 0 || i % 3 == 0)) continue;
    if (vis[getp(i)]) continue;
    for (int j = i + i; j <= n; j += i)
      if (j % 2 != 0 && j % 3 != 0) vis[getp(j)] = 1;
    unsigned int f = A * i * i * i + B * i * i + C * i + D;
    int x = n;
    while (x >= i) {
      ans += x / i * f;
      x /= i;
    }
  }
  printf("%u\n", ans);
  return 0;
}
