#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:210886422")
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000007;
const double EPS = 1e-11;
const int HASH_POW = 29;
const long double PI = acos(-1.0);
mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
long long nextLong(long long l, long long r) {
  uniform_int_distribution<long long> foo(l, r);
  return foo(rnd);
}
double nextDouble(double l, double r) {
  uniform_real_distribution<double> foo(l, r);
  return foo(rnd);
}
double workTime() { return double(clock()) / CLOCKS_PER_SEC; }
void myReturn(int code = 0) { exit(code); }
const int MAX_SQRT = 20000;
const int S = 30000;
bool nprime[MAX_SQRT], bl[S];
int primes[MAX_SQRT], cnt;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  unsigned int a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  int nsqrt = (int)sqrt(n + 0.0) + 1;
  for (int i = 2; i <= nsqrt; ++i) {
    if (!nprime[i]) {
      primes[cnt++] = i;
      for (int j = i * i; j <= nsqrt; j += i) {
        nprime[j] = true;
      }
    }
  }
  unsigned int ans = 0;
  for (int k = 0, maxk = n / S; k <= maxk; ++k) {
    memset(bl, 0, sizeof bl);
    int start = k * S;
    for (int i = 0; i < cnt; ++i) {
      int start_idx = (start + primes[i] - 1) / primes[i];
      int j = max(start_idx, 2) * primes[i] - start;
      for (; j < S; j += primes[i]) {
        bl[j] = true;
      }
    }
    if (k == 0) {
      bl[0] = bl[1] = true;
    }
    for (int i = 0; i < S && start + i <= n; ++i) {
      if (!bl[i]) {
        unsigned int p = start + i, q = 1, f = 0;
        unsigned int cnt = 0, foo = n;
        while (foo > 0) {
          cnt += foo / p;
          foo /= p;
        }
        f += d * q;
        q *= p;
        f += c * q;
        q *= p;
        f += b * q;
        q *= p;
        f += a * q;
        ans += f * cnt;
      }
    }
  }
  cout << ans << endl;
  myReturn();
}
