30uint64_t
lcmSum(
const uint16_t& num) {
31 uint64_t i = 0, j = 0;
32 std::vector<uint64_t> eulerTotient(num + 1);
33 std::vector<uint64_t> sumOfEulerTotient(num + 1);
36 for (i = 1; i <= num; i++) {
41 for (i = 2; i <= num; i++) {
42 if (eulerTotient[i] == i) {
43 for (j = i; j <= num; j += i) {
44 eulerTotient[j] = eulerTotient[j] / i;
45 eulerTotient[j] = eulerTotient[j] * (i - 1);
51 for (i = 1; i <= num; i++) {
52 for (j = i; j <= num; j += i) {
53 sumOfEulerTotient[j] += eulerTotient[i] * i;
57 return ((sumOfEulerTotient[num] + 1) * num) / 2;