#include <bits/stdc++.h>
using namespace std;
const int SQR = 17321, S_SIZE = 32768 * 16;
int n;
bool is_prime[SQR];
char sieve[S_SIZE / 16], unset[16];
unsigned int A, B, C, D, wynik;
vector<int> Primes, Multiples;
inline void insert(unsigned int p) {
  unsigned int s = n, blep = 0;
  while (s >= p) blep += (s = s / p);
  wynik += blep * (A * p * p * p + B * p * p + C * p + D);
}
void Sieve() {
  for (int i = 0; i < 16; i++) unset[i] = ~(1 << (i >> 1));
  int sqN = sqrt(n);
  memset(is_prime, true, sizeof is_prime);
  insert(2);
  int i = 3, s = 3;
  for (int low = 0; low <= n; low += S_SIZE) {
    memset(sieve, 255, sizeof sieve);
    int high = min(n, low + S_SIZE - 1);
    for (; i * i <= high; i += 2) {
      if (is_prime[i]) {
        Primes.push_back(i);
        int j = i * i;
        Multiples.push_back(j - low);
        for (int k = (i << 1); j <= sqN; j += k) is_prime[j] = true;
      }
    }
    for (int i = 0; i < (int)Primes.size(); i++) {
      int j = Multiples[i];
      for (int k = (Primes[i] << 1); j < S_SIZE; j += k)
        sieve[j >> 4] &= unset[j & 15];
      Multiples[i] = j - S_SIZE;
    }
    for (; s <= high; s += 2) {
      int j = s - low;
      if (sieve[j >> 4] & (1 << ((j & 15) >> 1))) insert(s);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> A >> B >> C >> D;
  Sieve();
  cout << wynik << endl;
  getchar();
  getchar();
  return 0;
}
