#include <bits/stdc++.h>
using namespace std;
vector<int> P;
unsigned int A, B, C, D;
int n;
unsigned int F(int p) {
  unsigned int x = 0;
  int n1 = n;
  while (n1 > 0) {
    x += n1 / p;
    n1 /= p;
  }
  return (((A * p + B) * p + C) * p + D) * x;
}
int main() {
  scanf("%d%u%u%u%u", &n, &A, &B, &C, &D);
  P.push_back(2);
  int TT = 100000;
  for (int i = 3; i < TT; i++) {
    bool g = true;
    for (int j = 0; j < P.size(); j++)
      if (i % P[j] == 0) {
        g = false;
        break;
      }
    if (g) P.push_back(i);
  }
  int t = 0;
  int CC[100000];
  t -= P.size();
  unsigned int ans = 0;
  for (int i = 0; i < P.size(); i++) ans += F(P[i]);
  for (int k = TT; k <= n; k += TT) {
    memset(CC, 0, sizeof(CC));
    CC[0] = 1;
    for (int i = 0; i < P.size(); i++) {
      for (int j = P[i] - (k % P[i]); j < TT; j += P[i]) CC[j] = 1;
    }
    for (int i = 0; i < TT; i++)
      if (CC[i] == 0) {
        int j = k + i;
        if (j > n) break;
        ans += F(j);
      }
  }
  printf("%u\n", ans);
  return 0;
}
