#include <bits/stdc++.h>
using namespace std;
bitset<100000003> bit;
unsigned n, a, b, c, d;
unsigned Get(unsigned x) {
  unsigned temp1 = (a * x * x * x + b * x * x + c * x + d) % 4294967296;
  unsigned temp2 = 0;
  unsigned y = x;
  for (unsigned i = 1; i <= n / x; i *= x) temp2 += n / (i * x);
  return temp1 * temp2 % 4294967296;
}
int main() {
  cin >> n >> a >> b >> c >> d;
  unsigned int ans;
  ans = Get(2) + Get(3);
  bit.reset();
  for (unsigned i = 5; i <= n; ++i) {
    if (i % 3 == 0 || i % 2 == 0) continue;
    if (bit[i / 3] == 0) {
      ans = (ans + Get(i)) % 4294967296;
      for (unsigned j = i; j <= n / i; ++j) {
        if (i * j % 3 == 0 || i * j % 2 == 0) continue;
        bit[i * j / 3] = 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
