#include <bits/stdc++.h>
using namespace std;
const long long big = 1000000007;
const long long mod = 998244353;
unsigned int n, m, k, T, q;
unsigned int a, b, c, d;
unsigned int const len = 10000003;
vector<unsigned int> primes;
bitset<len> B;
void zero() { B = 0; }
unsigned int f(unsigned int i) { return i * (i * (i * a + b) + c) + d; }
unsigned int start(unsigned int p, unsigned int i) {
  if (i % p == 0) return i;
  return (i - i % p + p);
}
bool isprime(unsigned int p) {
  int lim = min((int)(primes).size(), 10);
  for (int c1 = 0; c1 < lim; c1++) {
    if (p == primes[c1]) return 1;
    if (p % primes[c1] == 0) return 0;
  }
  for (int c1 = 0; c1 < (int)(primes).size() && primes[c1] * primes[c1] <= p;
       c1++) {
    if (p % primes[c1] == 0) return 0;
  }
  return 1;
}
int main() {
  cin >> n >> a >> b >> c >> d;
  k = 0;
  unsigned int ans = 0;
  for (int c1 = 2; c1 <= n; c1++) {
    if (c1 % len == 0 && c1 != 0) {
      zero();
      k++;
      for (int c2 = 0; c2 < (int)(primes).size(); c2++) {
        for (int c3 = start(primes[c2], c1) - k * len; c3 < len;
             c3 += primes[c2]) {
          B[c3] = 1;
        }
      }
    }
    if (B[c1 - k * len] == 0) {
      long long t = c1;
      while (t <= n) {
        ans += (n / t) * f(c1);
        t *= c1;
      }
      if (c1 < 20000) primes.push_back(c1);
      for (int c2 = c1; c2 < len + k * len; c2 += c1) {
        B[c2 - k * len] = 1;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
