#include <bits/stdc++.h>
int ATTENTION() {
http:
  return 0;
}
using namespace std;
const int iinf = 0x7fffffff;
const long long linf = ~(1LL << 63);
template <typename T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  if (a < b) return gcd(b, a);
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long qpow(long long a, long long n, long long mod) {
  a %= mod;
  long long ans = 1LL;
  while (n) {
    if (n & 1) ans = (ans * a % mod);
    a = (a * a % mod);
    n >>= 1;
  }
  return ans;
}
inline long long rev(long long a, long long p) { return qpow(a, p - 2, p); }
template <typename T>
inline void BPS(T* DST, T* SRC, int N, int s = 0) {
  DST[s] = SRC[s];
  for (int i = 1; i < N; i++) DST[s + i] = DST[s + i - 1] + SRC[s + i];
}
inline int in() {
  int x;
  cin >> x;
  return x;
}
inline void tic() {}
inline void toc() {}
bitset<100000001> is_prime;
int n, A, B, C, D;
void unset_prime(unsigned int v) { is_prime.reset(v / 3); }
unsigned int f(unsigned int x) {
  return ((((unsigned int)A * x + (unsigned int)B)) * x + (unsigned int)C) * x +
         (unsigned int)D;
}
int main() {
  scanf("%u%u%u%u%u", &n, &A, &B, &C, &D);
  is_prime.set();
  unsigned int res = 0;
  unsigned int t = n;
  unsigned int p2 = 2;
  unsigned int fp = f(2);
  while (t >= p2) {
    res += t / p2 * fp;
    p2 *= 2;
  }
  p2 = 3;
  fp = f(3);
  while (t >= p2) {
    res += t / p2 * fp;
    p2 *= 3;
  }
  for (unsigned int i = 5; i <= n; i += 2) {
    if (is_prime[i / 3] == 0) {
      if (i % 3 == 1) i += 2;
      continue;
    }
    for (unsigned int j = 5 * i, k = 5; j <= n; j += 2 * i, k += 2) {
      unset_prime(j);
      if (k % 3 == 1) {
        k += 2;
        j += 2 * i;
      }
    }
    t = n;
    long long pi = i;
    fp = f(i);
    while (t >= pi) {
      res += t / pi * fp;
      pi *= i;
    }
    if (i % 3 == 1) i += 2;
  }
  printf("%u\n", res);
  return 0;
}
