#include <bits/stdc++.h>
using namespace std;
const int maxm = 100000000;
int n;
unsigned int A, B, C, D, ans;
bitset<maxm + 5> vis;
inline unsigned int Count(int n, int p) {
  unsigned int sum = 0;
  while (n) sum += (n /= p);
  return sum;
}
int main() {
  scanf("%d%u%u%u%u", &n, &A, &B, &C, &D);
  for (int i = 2; i <= n; i += (i & 1) + 1)
    if ((i == 3 || i % 3) && !vis[((i) - (i) / 2 - (i) / 3 + (i) / 6)]) {
      unsigned int F = A * i * i * i + B * i * i + C * i + D;
      ans += F * Count(n, i);
      for (int j = i; j <= n; j += i)
        if (j % 2 && j % 3) vis[((j) - (j) / 2 - (j) / 3 + (j) / 6)] = true;
    }
  return printf("%u\n", ans), 0;
}
