/* -*- coding: utf-8 -*- * * 3388.cc: No.3388 Sum of Function - yukicoder */ #include #include #include using namespace std; /* constant */ /* typedef */ using vb = vector; using vi = vector; /* global variables */ vb primes; vi pnums; /* subroutines */ int gen_primes(int maxp) { primes.assign(maxp + 1, true); primes[0] = primes[1] = false; int p; for (p = 2; p * p <= maxp; p++) if (primes[p]) { pnums.push_back(p); for (int q = p * p; q <= maxp; q += p) primes[q] = false; } for (; p <= maxp; p++) if (primes[p]) pnums.push_back(p); return (int)pnums.size(); } int f(int x) { return x * x * x - x * x + x + 1; } /* main */ int main() { int a, b; scanf("%d%d", &a, &b); gen_primes(b); int sum = 0; for (auto p: pnums) if (a <= p && p <= b) sum += f(p); printf("%d\n", sum); return 0; }