#include <bits/stdc++.h>
using namespace std;
const int desll[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const long long mod = 1e9 + 7;
const int maxn = 1e4;
const int maxm = 3e8 + 7;
const double eps = 1e-4;
int m, n;
bitset<100000001> bi;
unsigned int a, b, c, d;
unsigned int func(unsigned int x) {
  return a * x * x * x + b * x * x + c * x + d;
}
unsigned int get(unsigned int x) {
  unsigned int temp = 0;
  long long mid = x;
  while (mid <= n) {
    temp += n / mid;
    mid *= x;
  }
  return func(x) * temp;
}
int main() {
  cin >> n >> a >> b >> c >> d;
  bi.reset();
  unsigned int ans = get(2) + get(3);
  for (unsigned int i = 5; i <= n; i++) {
    if (i % 2 == 0 || i % 3 == 0) continue;
    if (bi[i / 3] == 0) {
      ans += get(i);
      for (long long j = (long long)i * i; j <= n; j += i) {
        if (j % 2 == 0 || j % 3 == 0) continue;
        bi[j / 3] = 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
