#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007LL;
long long large = 2000000000000000000LL;
bitset<20011> vis;
vector<int> primes;
void sieve(long long n) {
  vis.set();
  vis[0] = 0;
  vis[1] = 0;
  for (long long i = 2; i <= n; i++) {
    if (vis[i]) primes.push_back((int)i);
    for (int j = 0; j < (int)primes.size() && i * primes[j] <= n; j++) {
      vis[i * primes[j]] = 0;
      if (i % primes[j] == 0) break;
    }
  }
}
int main() {
  int n;
  unsigned int a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  sieve(20010);
  unsigned int ans = 0;
  int sq = 20000;
  int p = 2;
  while (p < n + 1) {
    int l = p;
    int r = min(l + sq, n + 1);
    int sz = r - l;
    vector<bool> vis(sz, true);
    for (int i = 0; i < (int)primes.size(); i++) {
      int x = primes[i];
      int y = l;
      y = max(y, 2 * x);
      y = ((y - 1) / x + 1) * x;
      while (y < r) {
        vis[y - l] = false;
        y += x;
      }
    }
    for (int i = 0; i < sz; i++) {
      if (vis[i]) {
        unsigned int x = i + l;
        if (x < 2) continue;
        unsigned int temp = a * x * x * x + b * x * x + c * x + d;
        unsigned int d = x;
        while (n / d) {
          ans += temp * (n / d);
          if (n / x < d) break;
          d *= x;
        }
      }
    }
    p += sq;
  }
  cout << ans << endl;
  return 0;
}
