#include <bits/stdc++.h>
using namespace std;
int start, ed = 0, sz = 130000000;
long long marked[(130000000 / 64) + 5];
vector<int> primes;
inline bool check(int pos) { return !(marked[pos / 64] & (1LL << (pos % 64))); }
int pos;
bool isPrime(int n) {
  if (n != 2 and n % 2 == 0) return false;
  int sq = sqrt(n);
  for (int i = 3; i <= sq; i += 2) {
    if (n % i == 0) return false;
  }
  return true;
}
void genPrimes(int n) {
  int sq = sqrt(n);
  for (int i = 2; i <= sq; i++) {
    if (isPrime(i)) primes.push_back(i);
  }
}
void segSieve(int L, int R) {
  if (L <= 1 and R >= 1)
    pos = 1 - start, marked[pos / 64] |= (1LL << (pos % 64));
  int sq = sqrt(R), st;
  for (int i = 0; primes[i] <= sq and i < primes.size(); i++) {
    if (L <= primes[i])
      st = primes[i] + primes[i];
    else
      st = ((L + primes[i] - 1) / primes[i]) * primes[i];
    for (int j = st; j <= R; j += primes[i]) {
      pos = j - start, marked[pos / 64] |= (1LL << (pos % 64));
    }
  }
}
unsigned int ans = 0, a, b, c, d;
inline unsigned int F(unsigned int x) { return x * (x * (a * x + b) + c) + d; }
void call(int n) {
  int sum = 0;
  long long cur;
  for (int i = 2; i <= n; i++) {
    if (i > ed) {
      memset(marked, 0, sizeof(marked));
      start = ed + 1;
      ed = start + sz - 1;
      segSieve(start, min(ed, 300000000));
    }
    if (!check(i - start)) continue;
    cur = i, sum = 0;
    while (cur <= n) {
      sum += (n / cur);
      cur *= i;
    }
    ans += sum * F(i);
  }
}
int main() {
  int n;
  cin >> n >> a >> b >> c >> d;
  genPrimes(n);
  call(n);
  cout << ans << endl;
  return 0;
}
