#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
using namespace std;
bitset<100000001> isPrime;
unsigned int N, n, A, B, C, D;
unsigned int sum, a, p, num, add, add_;
inline void fact(int x) {
  for (a = 0, N = n; N; N /= x) a += N / x;
  sum += a * (A * x * x * x + B * x * x + C * x + D);
}
int main() {
  scanf("%u %u %u %u %u", &n, &A, &B, &C, &D);
  fact(2);
  fact(3);
  for (int p = 5, add = 2; p <= n; p += add, add = 6 - add) {
    if (isPrime[p / 3]) continue;
    fact(p);
    if (p > (n + p - 1) / p) continue;
    for (int num = p * p, add_ = add; num <= n;
         num += p * add_, add_ = 6 - add_) {
      isPrime[num / 3] = 1;
    }
  }
  printf("%u", sum);
  return 0;
}
