#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
int nn, a, b, c, d;
unsigned int eval(unsigned int p) { return d + p * (c + p * (b + p * a)); }
unsigned int ans = 0;
const int L1D_CACHE_SIZE = 16384;
void segmented_sieve(int limit) {
  int sqrt = (int)std::sqrt(limit);
  int segment_size = std::max(sqrt, L1D_CACHE_SIZE);
  int s = 3;
  int n = 3;
  std::vector<char> is_prime(sqrt + 1, 1);
  for (int i = 2; i * i <= sqrt; i++)
    if (is_prime[i])
      for (int j = i * i; j <= sqrt; j += i) is_prime[j] = 0;
  std::vector<char> sieve(segment_size);
  std::vector<int> primes;
  std::vector<int> next;
  for (int low = 0; low <= limit; low += segment_size) {
    fill(sieve.begin(), sieve.end(), 1);
    int high = min(low + segment_size - 1, limit);
    for (; s * s <= high; s += 2) {
      if (is_prime[s]) {
        primes.push_back((int)s);
        next.push_back((int)(s * s - low));
      }
    }
    for (int i = 0; i < primes.size(); i++) {
      int j = next[i];
      for (int k = primes[i] * 2; j < segment_size; j += k) sieve[j] = 0;
      next[i] = j - segment_size;
    }
    for (; n <= high; n += 2)
      if (sieve[n - low]) {
        unsigned int val = eval(n);
        for (long long k = n; k <= nn; k *= n) {
          ans += (nn / k) * val;
        }
      }
  }
  unsigned int val = eval(2);
  for (long long k = 2; k <= nn; k *= 2) {
    ans += (nn / k) * val;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> nn >> a >> b >> c >> d;
  segmented_sieve(nn);
  cout << ans << '\n';
  return 0;
}
