#include <bits/stdc++.h>
using namespace std;
struct {
  uint32_t A, B, C, D;
} coef;
uint32_t calcF(uint32_t p) {
  return coef.D + p * (coef.C + p * (coef.B + p * coef.A));
}
uint32_t calcVal(uint32_t n, uint32_t p) {
  uint32_t tmp = 0;
  while ((n /= p) > 0) {
    tmp += n;
  }
  tmp *= calcF(p);
  return tmp;
}
bitset<50000000> A, B;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  uint32_t n;
  cin >> n >> coef.A >> coef.B >> coef.C >> coef.D;
  uint32_t ans = 0;
  for (uint32_t p = 2; p <= n; p++) {
    if (p <= 3 || p % 6 == 5 || p % 6 == 1) {
      if (p % 6 == 5 && A[p / 6] == 1) continue;
      if (p % 6 == 1 && B[p / 6 - 1] == 1) continue;
      ans += calcVal(n, p);
      for (uint32_t x = p; x <= n; x += p) {
        if (x % 6 == 5) {
          A[x / 6] = 1;
        } else if (x % 6 == 1) {
          B[x / 6 - 1] = 1;
        }
      }
    }
  }
  cout << ans << "\n";
}
