#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1LL << 32;
const long long MAXN = 17322;
const long long MAXT = 3 * 1e8 + 1;
int hp[] = {2, 3, 5};
const int DEN = 30;
const int BS = 8;
const long long SIEVE_SIZE = (MAXT + DEN - 1) / DEN;
bitset<SIEVE_SIZE> notp[BS];
inline int getind(int mod) {
  if (mod == 1) return 0;
  if (mod == 7) return 1;
  if (mod == 11) return 2;
  if (mod == 13) return 3;
  if (mod == 17) return 4;
  if (mod == 19) return 5;
  if (mod == 23) return 6;
  if (mod == 29) return 7;
  return -1;
}
inline bool isprime(int x) {
  return x == 2 || x == 3 || x == 5 ||
         ((x & 1) && (x % 3 != 0) && (x % 5 != 0) &&
          !notp[getind(x % DEN)][x / DEN]);
}
void sieve(int n) {
  for (int i = 7; i * i <= n; i++) {
    if (isprime(i)) {
      for (int mn = i * i; mn <= n; mn += i) {
        int ind = getind(mn % DEN);
        if (ind != -1) notp[ind][mn / DEN] = 1;
      }
    }
  }
}
int main() {
  int n, a, b, c, d;
  scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
  long long cc[4];
  cc[0] = d;
  cc[1] = c;
  cc[2] = b;
  cc[3] = a;
  sieve(n);
  long long ans = 0;
  for (int i = 2; i <= n; i++) {
    if (isprime(i)) {
      long long p = 1;
      long long re = 0;
      for (int j = 0; j < (4); j++) {
        re = (re + ((p * cc[j]) % MOD)) % MOD;
        p = (p * i) % MOD;
      }
      long long f = 0;
      long long co = n;
      while (co) {
        f = (f + co / i) % MOD;
        co /= i;
      }
      ans = (ans + ((f * re) % MOD)) % MOD;
    }
  }
  printf("%lld", ans);
}
