#include <bits/stdc++.h>
using namespace std;
const long long mod = (1LL) << (32LL);
const int M = 5000;
long long power(long long x, unsigned long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
inline void MOD(long long *x) {
  long long y = *x;
  if (y >= mod) y -= (y / mod) * mod;
  *x = y;
}
long long a, b, c, d, n, N, ans = 0;
vector<int> prime;
void simpleSieve(long long limit) {
  bool mark[limit + 1];
  memset(mark, true, sizeof(mark));
  long long p, i;
  for (p = 2; p * p < limit; p++) {
    if (mark[p] == true) {
      for (i = p * p; i < limit; i += p) mark[i] = false;
    }
  }
  for (p = 2; p < limit; p++) {
    if (mark[p] == true) {
      prime.push_back(p);
      long long x1 = c * p + d;
      MOD(&x1);
      long long x2 = p * p;
      MOD(&x2);
      long long x3 = x2;
      x2 *= p;
      MOD(&x2);
      x2 *= a;
      MOD(&x2);
      x3 *= b;
      MOD(&x3);
      long long x = x1 + x2 + x3;
      MOD(&x);
      long long y = 0;
      for (long long pw = p; pw <= n; pw *= p) y += n / pw;
      MOD(&y);
      long long z = x * y;
      MOD(&z);
      ans += z;
      MOD(&ans);
    }
  }
}
void segmentedSieve() {
  long long limit = floor(sqrt(N)) + 1;
  simpleSieve(limit);
  long long low = limit;
  long long high = 2 * limit;
  long long i, j, p;
  while (low < N) {
    if (high >= N) high = N;
    bool mark[limit + 1];
    memset(mark, true, sizeof(mark));
    for (i = 0; i < prime.size(); i++) {
      long long loLim = floor(low / prime[i]) * prime[i];
      if (loLim < low) loLim += prime[i];
      for (j = loLim; j < high; j += prime[i]) mark[j - low] = false;
    }
    for (p = low; p < high; p++) {
      if (mark[p - low] == true) {
        long long x1 = c * p + d;
        MOD(&x1);
        long long x2 = p * p;
        MOD(&x2);
        long long x3 = x2;
        x2 *= p;
        MOD(&x2);
        x2 *= a;
        MOD(&x2);
        x3 *= b;
        MOD(&x3);
        long long x = x1 + x2 + x3;
        MOD(&x);
        long long y = 0;
        for (long long pw = p; pw <= n; pw *= p) y += n / pw;
        MOD(&y);
        long long z = x * y;
        MOD(&z);
        ans += z;
        MOD(&ans);
      }
    }
    low = low + limit;
    high = high + limit;
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  cin >> n >> a >> b >> c >> d;
  N = n + 1;
  segmentedSieve();
  cout << ans;
  return 0;
}
