#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma loop_opt(on)
using namespace std;
bitset<100000000 + 59> p;
unsigned long long n, a, b, c, d;
inline unsigned long long cal(unsigned long long x) {
  return ((((a * x % (1ll << 32)) + b) % (1ll << 32) * x % (1ll << 32) + c) %
              (1ll << 32) * x % (1ll << 32) +
          d) %
         (1ll << 32);
}
inline unsigned long long cnt(unsigned long long x, unsigned long long n) {
  register unsigned long long temp = 0;
  n /= x;
  while (n > 0) {
    temp += n;
    n /= x;
  }
  return temp * cal(x) % (1ll << 32);
}
unsigned long long ans;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> a >> b >> c >> d;
  ans = (cnt(2, n) + cnt(3, n)) % (1ll << 32);
  for (unsigned long long i = 5; i <= n; i += (i % 6 == 1 ? 4 : 2)) {
    if (i % 6 == 1 && !p[(i - 1) / 6 * 2]) {
      ans = (ans + cnt(i, n)) % (1ll << 32);
      for (unsigned long long j = i * i; j <= n;
           j += (j % 6 == 1 ? 4 * i : 2 * i)) {
        if (j % 6 == 1)
          p[(j - 1) / 6 * 2] = 1;
        else
          p[(j - 5) / 6 * 2 + 1] = 1;
      }
    } else if (i % 6 == 5 && !p[(i - 5) / 6 * 2 + 1]) {
      ans = (ans + cnt(i, n)) % (1ll << 32);
      for (unsigned long long j = i * i; j <= n;
           j += (j % 6 == 1 ? 2 * i : 4 * i)) {
        if (j % 6 == 1)
          p[(j - 1) / 6 * 2] = 1;
        else
          p[(j - 5) / 6 * 2 + 1] = 1;
      }
    }
  }
  cout << ans;
}
