#include <bits/stdc++.h>
using namespace std;
long long n;
bitset<100000008> siv;
void gen() {
  for (long long i = 6, ii = 0;; i += 6, ii += 2) {
    long long val;
    val = i - 1;
    if (val > n) break;
    if (!siv.test(ii)) {
      for (long long j = 6;; j += 6) {
        long long kal;
        long long jal;
        long long dec;
        kal = j - 1;
        jal = kal * val;
        if (jal > n) break;
        dec = (jal - 1) / 3 - 1;
        siv.set(dec);
        kal = j + 1;
        jal = kal * val;
        if (jal > n) break;
        dec = (jal - 5) / 3;
        siv.set(dec);
      }
    }
    val = i + 1;
    if (val > n) break;
    if (!siv.test(ii + 1)) {
      for (long long j = 6;; j += 6) {
        long long kal;
        long long jal;
        long long dec;
        kal = j - 1;
        jal = kal * val;
        if (jal > n) break;
        dec = (jal - 5) / 3;
        siv.set(dec);
        kal = j + 1;
        jal = kal * val;
        if (jal > n) break;
        dec = (jal - 1) / 3 - 1;
        siv.set(dec);
      }
    }
  }
}
long long a, b, c, d;
long long fun(long long x) {
  long long val = (((((((((a * x) % ((1LL) << 32) + b) % ((1LL) << 32)) * x) %
                           ((1LL) << 32) +
                       c) %
                      ((1LL) << 32)) %
                     ((1LL) << 32)) *
                    x) %
                       ((1LL) << 32) +
                   d) %
                  ((1LL) << 32);
  long long cnt = 0;
  long long pw = x;
  while (pw <= n) {
    cnt += n / pw;
    cnt %= ((1LL) << 32);
    pw *= x;
  }
  val *= cnt;
  val %= ((1LL) << 32);
  return val;
}
int main() {
  cin >> n;
  cin >> a >> b >> c >> d;
  gen();
  long long ans = 0;
  ans += fun(2);
  ans %= ((1LL) << 32);
  ans += fun(3);
  ans %= ((1LL) << 32);
  for (long long i = 0;; i++) {
    long long val = (3 * (i + (i & 1)) + 1 + 4 * ((i & 1) ^ 1));
    if (val > n) break;
    if (!siv.test(i)) {
      ans += fun(val);
      ans %= ((1LL) << 32);
    }
  }
  cout << ans << endl;
  return 0;
}
