#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
unsigned int n, A, B, C, D, ans;
unsigned int get(unsigned int first) {
  return ((A * first + B) * first + C) * first + D;
}
unsigned int cnt(unsigned int first) {
  unsigned int xx = first, ret = 0;
  while (true) {
    ret += n / first;
    if ((long long)first * (long long)xx > (long long)n) break;
    first *= xx;
  }
  return ret;
}
void f(unsigned int first) { ans += cnt(first) * get(first); }
bitset<50000100> five, one;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  cin >> n >> A >> B >> C >> D;
  if (n >= 2) f(2);
  if (n >= 3) f(3);
  for (unsigned int i = 0; i < 50000100; i++) five[i] = one[i] = true;
  for (unsigned int i = 5; i <= n; i++) {
    if (i % 6 == 1 && one[i / 6]) {
      f(i);
      for (unsigned int j = i + i; j <= n; j += i) {
        if (j % 6 == 1) one[j / 6] = false;
        if (j % 6 == 5) five[j / 6] = false;
      }
    }
    if (i % 6 == 5 && five[i / 6]) {
      f(i);
      for (unsigned int j = i + i; j <= n; j += i) {
        if (j % 6 == 1) one[j / 6] = false;
        if (j % 6 == 5) five[j / 6] = false;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
