Lcm sum sum

j = 1 10 3 i = 1 10 4 lcm ( i , j ) = ? \large\sum _{ j=1 }^{ { 10 }^{ 3 } }{ \sum _{ i=1 }^{ { 10 }^{ 4 } }{ \text{lcm}(i,j) } } = \ ?


The answer is 18286263868098.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<iostream>
using namespace std;

int gcd (  int a, int b )
{
  int c;
  while ( a != 0 ) {
     c = a; a = b%a;  b = c;
  }
  return b;
}

int lcm ( int a, int b)
{
    return a*b/gcd(a,b);
}

int main(){
int i,j;
long long int sum=0;
for(j=1;j<=1000;j++){
    for(i=1;i<=10000;i++){
        sum+=lcm(i,j);
    }
}
cout<<sum;

}

Bill Bell
Nov 9, 2015

Never re-invent the wheel. The author of this module is a much better programmer than most of us could hope to be.

1
2
3
4
5
6
7
8
from gmpy2 import lcm

total=0
for j in range(1,1+10**3):
    for i in range(1,1+10**4):
        total+=lcm(i,j)

print total

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...