#include <bits/stdc++.h>
using namespace std;
long long int n, a, b, c, d;
long long int solve(long long int p) {
  long long int coef = 0;
  long long int v = n;
  while (v > 0) {
    coef += v / p;
    v /= p;
  }
  return coef * (d + p * (c + p * (b + p * a)));
}
const int B = 1000000;
int pr[B];
void init(void) {
  for (int i = (int)(2); i < (int)(B); i++) pr[i] = 1;
  for (int i = 2; i * i < B; ++i) {
    if (pr[i] == 0) continue;
    for (int j = 2; j * i < B; ++j) {
      pr[i * j] = 0;
    }
  }
}
int sieve[B];
int main(void) {
  init();
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> a >> b >> c >> d;
  long long int ans = 0;
  vector<int> primes;
  for (int i = (int)(2); i < (int)(B); i++) {
    if (pr[i]) {
      primes.push_back(i);
      ans += solve(i);
    }
  }
  for (int i = B; i <= n; i += B) {
    for (int j = (int)(0); j < (int)(B); j++) sieve[j] = 1;
    for (long long int p : primes) {
      long long int lo = (i + p - 1) / p * p;
      long long int hi = (i + B - 1) / p * p;
      for (long long int j = lo; j <= hi; j += p) {
        sieve[j - i] = 0;
      }
    }
    for (int j = (int)(0); j < (int)(B); j++) {
      if (sieve[j]) {
        ans += solve(i + j);
      }
    }
  }
  cout << (unsigned int)ans << endl;
}
