## Amazon Interview Question

SDE1s**Country:**India

```
public class SumOfIntegers {
public static void main(String[] args) {
int[] arr = new int[] {1,2,3};
long sum = 0;
for(int i=0;i<arr.length;i++){
int k= (i+1)%3;
sum+=arr[i]%arr[k];
sum+=arr[k]%arr[i];
}
sum+=sum%(Math.pow(10, 9)+7);
System.out.println(sum);
}
```

}

```
import java.util.*;
public class Solution
{
public static void main(String[] args)
{
int[] A = new int[] {1, 2, 3};
int n = A[A.length-1];
long sum = 0;
for(int i = 1; i <= n; i++)
{
int q = n / i;
int r = n % i;
sum += (long)((i*(i-1)/2)*q + r*(r+1)/2);
}
System.out.println(sum % (long)(Math.pow(10, 9)+7));
}
}
```

import java.util.*;

public class Solution

{

public static void main(String[] args)

{

int[] A = new int[] {1, 2, 3};

int n = A[A.length-1];

long sum = 0;

for(int i = 1; i <= n; i++)

{

int q = n / i;

int r = n % i;

sum += (long)((i*(i-1)/2)*q + r*(r+1)/2);

}

System.out.println(sum % (long)(Math.pow(10, 9)+7));

}

}

- lixx3527 July 27, 2019