#include <bits/stdc++.h>
using namespace std;
bitset<20001> b(0);
vector<long long> P;
long long n, A, B, C, D, ats = 0, M = (1LL << 32LL) - 1;
unsigned int F(unsigned int x) { return x * x * x * A + x * x * B + x * C + D; }
void sieve(long long L, long long R) {
  b = bitset<20001>(0);
  for (auto& p : P) {
    if (p > R) break;
    long long j = L + (p - L % p) % p;
    if (j == p) j += p;
    for (j; j <= R; j += p) b[j - L] = 1;
  }
  for (long long i = L; i <= R; i++)
    if (!b[i - L]) {
      long long cnt = 0, x = i;
      while (x <= n) {
        cnt = ((n / x) + cnt) & M;
        x *= i;
      }
      ats = (ats + ((cnt * F(i)) & M)) & M;
    }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  for (long long i = 2; i * i < 20001; i++)
    if (!b[i])
      for (long long j = 2 * i; j < 20001; j += i) b[j] = 1;
  for (long long i = 2; i < 20001; i++)
    if (!b[i]) P.push_back(i);
  cin >> n >> A >> B >> C >> D;
  for (long long i = 2; i <= n;) {
    sieve(i, min(i + 20000, n));
    i = min(i + 20000, n) + 1;
  }
  cout << ats;
}
