## 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);
}
```

}

```
public int solve(int[] array){
if(array.length<=1){
return 0;
}
int mod = (int)(1e9+7);
int sum = 0;
int pre_sum = array[0];
for(int i=1;i<array.length;i++){
sum += (pre_sum%array[i]);
pre_sum+=array[i];
sum %= mod;
pre_sum %= mod;
}
int suffix_sum = array[array.length-1];
for(int i=array.length-2;i>=0;i--){
sum += (suffix_sum%array[i]);
suffix_sum += array[i];
sum %= mod;
suffix_sum %= mod;
}
return 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));

}

}

can you explain me the idea behind your solution

- rajksingh3878 June 21, 2019