#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
const long long MOD = 4294967296;
const int MX = 100000000;
bitset<MX + 1> mrk;
int n, A, B, C, D;
long long ev(long long first) {
  long long tr = (first * first) % MOD;
  return (A * (tr * first) % MOD + B * tr + C * first + D) % MOD;
}
long long ct(long long base, long long cur) {
  return (n / cur) - (n / (cur * base));
}
int num(int idx) { return (idx / 6) * 2 + (idx % 6 == 1 ? 0 : 1); }
int main() {
  cin >> n >> A >> B >> C >> D;
  for (long long i = 4; i * i <= n; ++i) {
    if (mrk[num(i)] || !(i % 6 == 1 || i % 6 == 5)) continue;
    for (int j = i + i; j <= n; j += i) {
      if (!(j % 6 == 1 || j % 6 == 5)) continue;
      mrk[num(j)] = 1;
    }
  }
  long long all = 0;
  for (int i = 2; i <= n; ++i) {
    if (i != 2 && i != 3 && (!(i % 6 == 1 || i % 6 == 5))) continue;
    if (i != 2 && i != 3 && mrk[num(i)]) continue;
    long long e = i;
    int cnt = 0;
    while (e <= n) {
      cnt++;
      e *= i;
    }
    while (cnt) {
      e /= i;
      long long am = ct(i, e);
      all = (all + ev(i) * cnt * am) % MOD;
      cnt--;
    }
  }
  cout << all << endl;
  return 0;
}
