Divisible and Non-divisible Sums Difference

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
You are given positive integers n and m.
Define two integers, num1 and num2, as follows:
num1: The sum of all integers in the range[1, n]that are not divisible bym.num2: The sum of all integers in the range[1, n]that are divisible bym.
Return the integer num1 - num2.
LeetCode Problem - 2894
class Solution {
public int differenceOfSums(int n, int m) {
// Variables to store the sum of numbers not divisible by m (num1) and the sum of numbers divisible by m (num2)
int num1 = 0, num2 = 0;
// Iterate through numbers from 1 to n
for (int i = 1; i <= n; i++) {
// If the current number is not divisible by m, add it to num1
if (i % m != 0)
num1 += i;
// If the current number is divisible by m, add it to num2
else
num2 += i;
}
// Return the difference between num1 and num2
return num1 - num2;
}
}




