#include <bits/stdc++.h>
using namespace std;
unsigned int n, a, b, c, d, rez;
bool viz[30005];
vector<unsigned int> prime;
unsigned int fct(unsigned int x) { return d + x * (c + x * (b + x * a)); }
void adauga(unsigned int x) {
  unsigned int contr = 0;
  long long val = x;
  while (n / val > 0) {
    contr += n / val;
    val *= (x);
  }
  rez += fct(x) * contr;
}
void calc(unsigned int val) {
  unsigned int i, j;
  prime.clear();
  for (i = 2; i <= val; i++)
    if (!viz[i]) {
      prime.push_back(i);
      adauga(i);
      for (j = i * 2; j <= val; j += i) viz[j] = 1;
    }
}
void ext_eratos(unsigned int n) {
  unsigned int sqr = sqrt(n), l, r, m;
  calc(sqr);
  l = sqr + 1;
  while (l <= n) {
    r = min(n, l + sqr - 1);
    for (unsigned int i = 0; i < sqr; i++) viz[i] = 0;
    for (auto it = prime.begin(); it != prime.end(); ++it) {
      m = (l / (*it)) * (*it);
      while (m < l) m += *it;
      while (m <= r) {
        viz[m - l] = 1;
        m += *it;
      }
    }
    for (unsigned int i = 0; i <= r - l; i++)
      if (!viz[i]) adauga(i + l);
    l += sqr;
  }
}
int main() {
  cin >> n >> a >> b >> c >> d;
  ext_eratos(n);
  cout << rez;
  return 0;
}
