A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/d5/d83/lcm__sum_8cpp_source.html below:

TheAlgorithms/C++: math/lcm_sum.cpp Source File

Go to the documentation of this file. 30

uint64_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;

70

std::cout <<

"Passed Test 1!"

<< std::endl;

75

std::cout <<

"Passed Test 2!"

<< std::endl;

80

std::cout <<

"Passed Test 3!"

<< std::endl;

84

assert(test_4 == 616);

85

std::cout <<

"Passed Test 4!"

<< std::endl;

89

assert(test_5 == 1110);

90

std::cout <<

"Passed Test 5!"

<< std::endl;

int main()

Main function.

uint64_t lcmSum(const uint16_t &num)


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4