#include <bits/stdc++.h>
using namespace std;
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << " = " << h << endl;
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << " = " << h << ", ";
  _dbg(sdbg + 1, a...);
}
const int maxn = (2e6) + 7;
const int maxk = 20;
const int inf = (1e9) + 7;
const long long LLinf = (1e18) + 7;
const long double eps = 1e-9;
bitset<maxn> xd;
unsigned int res = 0;
int n, a, b, c, d;
int gdzie[maxn];
bool pier[maxn];
long long mod = (1LL << 32) - 1LL;
long long wiel(unsigned int x) {
  return (((((((x * x) & mod) * x) & mod) * a) & mod) + (((x * x) & mod) * b) +
          ((x * c) & mod) + d) &
         mod;
}
void dolicz(long long x) {
  if (x > 1 && x <= (long long)n) {
    long long ile = 0LL;
    long long cnt = x;
    while (cnt <= (long long)n) {
      ile += n / cnt;
      cnt *= (long long)x;
    }
    res += ile * wiel(x);
    res &= mod;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> a >> b >> c >> d;
  int cnt = 0;
  for (int i = 0; i < maxn; i++) gdzie[i] = 2 * i + maxn;
  for (int i = 2; i < maxn; i++)
    for (int j = i + i; j < maxn; j += i) pier[j] = 1;
  while (cnt <= n) {
    for (int i = 2; i * i <= n; i++)
      if (!pier[i])
        for (gdzie[i] -= maxn; gdzie[i] < maxn; gdzie[i] += i) xd[gdzie[i]] = 1;
    for (int i = 0; i < maxn; i++)
      if (xd[i] == 0) dolicz(i + cnt);
    xd.reset();
    cnt += maxn;
  }
  cout << res;
  return 0;
}
