#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
const int inf = numeric_limits<int>::max() / 2;
const long double eps = 1e-9;
const long double pi = acos(-1);
const int MAXN = (3e8 + 10) / 3;
int n;
unsigned int a, b, c, d;
bitset<MAXN> primes;
unsigned int f(unsigned int x) { return d + x * (c + x * (b + x * a)); }
int fict(int i) { return i - i / 2 - i / 3 + i / 6 - 1; }
void sieve() {
  primes.set();
  for (int i = 5; i * i <= n; i++) {
    if (i % 2 == 0 || i % 3 == 0) {
      continue;
    }
    if (primes[fict(i)]) {
      for (int j = i * i; j <= n; j += i) {
        if (j % 2 == 0 || j % 3 == 0) {
          continue;
        }
        primes[fict(j)] = 0;
      }
    }
  }
}
inline void solve() {
  sieve();
  unsigned int ans = 0;
  for (int p = 2; p <= n; p++) {
    if (p != 2 && p % 2 == 0 || p != 3 && p % 3 == 0) {
      continue;
    }
    if (p != 2 && p != 3 && !primes[fict(p)]) {
      continue;
    }
    unsigned int s = 0;
    unsigned int q = n / p;
    while (q >= 1) {
      s += q;
      q /= p;
    }
    ans += f(p) * s;
  }
  cout << ans << "\n";
}
inline void read() { cin >> n >> a >> b >> c >> d; }
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  read();
  solve();
  return 0;
}
