#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
const long long mod = 1 << 31;
bitset<100000001> is;
long long n;
long long a, b, c, d;
long long pw(long long x, int d) {
  long long ret = 1;
  for (int i = 0; i < d; ++i) ret *= x;
  return ret;
}
long long f(long long x) { return a * pw(x, 3) + b * pw(x, 2) + c * x + d; }
long long sol(long long x) {
  long long ans = 0;
  long long t = x;
  long long v = f(x);
  for (int j = 1; n / t; ++j) {
    ans = ans + (n / t - n / (t * x)) * j * v;
    t *= x;
  }
  return ans;
}
int main() {
  cin >> n >> a >> b >> c >> d;
  unsigned int ans = sol(2) + sol(3);
  for (int i = 2; i <= n; ++i) {
    if (i % 3 == 0 || i % 2 == 0) continue;
    if (is[i / 3] == 0) {
      ans += sol(i);
      for (int j = i + i; j <= n; j += i) {
        if (j % 2 == 0 || j % 3 == 0) continue;
        is[j / 3] = 1;
      }
    }
  }
  cout << ans << endl;
}
