#include <bits/stdc++.h>
using namespace std;
bitset<50000000> arr;
int primes[100100], pr = 0;
int n;
unsigned int A, B, C, D;
int main() {
  cin >> n >> A >> B >> C >> D;
  for (int i = 2; i <= 18000; i++) {
    arr[i] = 1;
  }
  for (int i = 2; i <= 18000; i++) {
    if (arr[i] == 0) continue;
    primes[pr++] = i;
    for (int j = i * i; j <= 18000; j += i) {
      arr[j] = 0;
    }
  }
  int st = 2;
  unsigned int sol = 0;
  while (st <= n) {
    int en = min(st + 40000000, n);
    int ln = en - st + 1;
    for (int i = 0; i < ln; i++) {
      arr[i] = 1;
    }
    for (int i = 0; i < pr; i++) {
      int beg = max(primes[i] * primes[i],
                    ((st + primes[i] - 1) / primes[i]) * primes[i]);
      for (int j = beg - st; j < ln; j += primes[i]) {
        arr[j] = 0;
      }
    }
    for (int i = 0; i < ln; i++) {
      if (arr[i] == 1) {
        unsigned int rep = 0;
        int cur_pr = st + i;
        while (cur_pr <= n) {
          rep += (unsigned int)(n / cur_pr);
          if (cur_pr > n / (st + i)) {
            break;
          } else {
            cur_pr *= (st + i);
          }
        }
        sol += rep * (A * (st + i) * (st + i) * (st + i) +
                      B * (st + i) * (st + i) + C * (st + i) + D);
      }
    }
    st = en + 1;
  }
  cout << sol << endl;
}
