#include <bits/stdc++.h>
using namespace std;
unsigned int n, a, b, c, d;
bitset<100000005> bs;
int calc(int x) {
  if (x % 2 == 0 || x % 3 == 0) return 0;
  return x - x / 2 - x / 3 + x / 6 - 1;
}
unsigned int f(unsigned int x) { return a * x * x * x + b * x * x + c * x + d; }
int main() {
  scanf("%u%u%u%u%u", &n, &a, &b, &c, &d);
  unsigned int res = 0;
  for (int i = 2; i <= n; i++) {
    if (!bs[calc(i)] || i == 2 || i == 3) {
      for (int j = i + i; j <= n; j += i) {
        bs[calc(j)] = 1;
      }
      unsigned int cnt = 0;
      unsigned int tmp = n;
      while (tmp) {
        cnt += tmp / i;
        tmp /= i;
      }
      res += cnt * f(i);
    }
  }
  printf("%u", res);
  return 0;
}
