uint64_t
lcmSum(
constuint16_t& num) {
31uint64_t i = 0, j = 0;
32std::vector<uint64_t> eulerTotient(num + 1);
33std::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) {
44eulerTotient[j] = eulerTotient[j] / i;
45eulerTotient[j] = eulerTotient[j] * (i - 1);
51 for(i = 1; i <= num; i++) {
52 for(j = i; j <= num; j += i) {
53sumOfEulerTotient[j] += eulerTotient[i] * i;
57 return((sumOfEulerTotient[num] + 1) * num) / 2;
70std::cout <<
"Passed Test 1!"<< std::endl;
75std::cout <<
"Passed Test 2!"<< std::endl;
80std::cout <<
"Passed Test 3!"<< std::endl;
84assert(test_4 == 616);
85std::cout <<
"Passed Test 4!"<< std::endl;
89assert(test_5 == 1110);
90std::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