#include <bits/stdc++.h>
using namespace std;
unsigned n, a, b, c, d;
bitset<100000001> bit;
unsigned get(unsigned x) {
  unsigned res = a * x * x * x + b * x * x + c * x + d;
  unsigned tmp = 0;
  for (unsigned i = 1; i <= n / x; i *= x) {
    tmp += n / (i * x);
  }
  return res * tmp;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> a >> b >> c >> d;
  unsigned sum = get(2) + get(3);
  for (unsigned i = 5; i <= n; i++) {
    if (i % 2 == 0 || i % 3 == 0) continue;
    if (bit[i / 3] == 0) {
      sum += get(i);
      for (unsigned j = i; j <= n / i; j++) {
        if (i * j % 2 == 0 || i * j % 3 == 0) continue;
        bit[i * j / 3] = 1;
      }
    }
  }
  cout << sum << "\n";
  return 0;
}
