#include <bits/stdc++.h>
using namespace std;
bitset<100000010> is;
int n;
unsigned int a, b, c, d;
inline unsigned int f(int x) { return a * x * x * x + b * x * x + c * x + d; }
inline unsigned int s(int x) {
  unsigned int res = 0;
  long long now = x;
  while (now <= n) {
    res += n / now;
    now *= x;
  }
  return res;
}
inline void bad() {
  puts("NNNOOO!!!");
  exit(0);
}
inline void check(int x) {
  int i;
  for (i = 2; i * i <= x; i++)
    if (x % i == 0) bad();
}
int main() {
  int i, j;
  unsigned int Ans = 0;
  cin >> n >> a >> b >> c >> d;
  for (i = 5; i <= n; i++)
    if (i % 6 == 1 || i % 6 == 5) {
      if (!is[i / 3]) {
        for (j = i * 2; j <= n; j += i)
          if (j % 6 == 1 || j % 6 == 5) is[j / 3] = 1;
      }
    }
  for (i = 2; i <= 3; i++) Ans += f(i) * s(i);
  for (i = 5; i <= n; i++)
    if (i % 6 == 1 || i % 6 == 5)
      if (!is[i / 3]) Ans += f(i) * s(i);
  cout << Ans << endl;
  return 0;
}
