#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1 << 32;
const int C = 3e4;
int n, a, b, c, d, prime[30005], p = 0, sito[30005];
long long wyn = 0;
long long efodiks(int x) {
  long long blep;
  blep = a;
  blep *= x;
  blep %= mod;
  blep += b;
  blep *= x;
  blep %= mod;
  blep += c;
  blep *= x;
  blep %= mod;
  blep += d;
  blep %= mod;
  return blep;
}
int adolf(int x) {
  int nghu = 0, base = x;
  while (x <= n) {
    nghu += n / x;
    if (x > n / base) break;
    x *= base;
  }
  return nghu;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> a >> b >> c >> d;
  for (int i = 2; i <= min(n, C); i++) {
    if (sito[i] == 0) {
      for (int j = i; j <= min(n, C); j += i) sito[j] = 1;
      p++;
      prime[p] = i;
      wyn += efodiks(i) * adolf(i);
      wyn %= mod;
    }
  }
  for (int i = min(n, C) + 1; i <= n; i++) {
    if (i % C == 1) {
      for (int j = 1; j <= C; j++) sito[j] = 0;
      for (int j = 3; j <= p; j++) {
        int josif = prime[j] - (i - 1) % prime[j];
        for (int k = josif; k <= C; k += prime[j]) sito[k] = 1;
      }
    }
    int chuj = i % C;
    if (chuj == 0) chuj = C;
    if ((sito[chuj] == 0) && (i % 2 != 0) && (i % 3 != 0)) {
      wyn += efodiks(i) * (n / i);
      wyn %= mod;
    }
  }
  cout << wyn << endl;
  return 0;
}
