#include <bits/stdc++.h>
using namespace std;
unsigned int n, ans, A, B, C, D, x, y;
int tot;
bitset<100000000> v;
int main() {
  scanf("%d%d%d%d%d", &n, &A, &B, &C, &D);
  x = A * 8 + B * 4 + C * 2 + D;
  y = 2;
  for (;;) {
    ans += n / y * x;
    if (y * 2 > n) break;
    y = y * 2;
  }
  x = A * 27 + B * 9 + C * 3 + D;
  y = 3;
  for (;;) {
    ans += n / y * x;
    if (y * 3 > n) break;
    y = y * 3;
  }
  for (unsigned int i = (5); i <= (n); i++)
    if ((i % 2) && (i % 3) && (!v[i / 3])) {
      for (unsigned int j = (5); j <= (n / i); j++)
        if ((j % 2) && (j % 3)) v[i * j / 3] = 1;
      x = A * i * i * i + B * i * i + C * i + D;
      y = i;
      for (;;) {
        ans += n / y * x;
        if (n / y < i) break;
        y = y * i;
      }
    }
  printf("%u\n", ans);
}
