Choose three integer numbers x, y, and z = c, respectively, where x>=1, y>=1, and z >=1 to get (a, b) pairs. The condition is (1<=a<=x, 1<=b<=y) where [ (a + b) % c = 0 ] , a and b are integer numbers.

Note: % is modulus

For example: x = 10, y = 5, z = 2

answer = 25 pairs

I will show a few pairs, (1,1), (1,3), (5,1), (7,3)…..etc

I got the answer using two loops in java programming language. This way is not effective when you use large numbers. It takes a lot of time to get the answer. Therefore, I tried to create a formula.

I discovered that when I do this xy / z, I get an approximate answer for large numbers while most of the time I get same answer for small numbers.

For example: x = 70001, y = 6022, z = 316

xy / z = (70001)(6022)/(316) = 1334006 but the correct answer = 1333997 exact pairs

Is there another formula that gives me exact pairs?

Note: % is modulus

For example: x = 10, y = 5, z = 2

answer = 25 pairs

I will show a few pairs, (1,1), (1,3), (5,1), (7,3)…..etc

I got the answer using two loops in java programming language. This way is not effective when you use large numbers. It takes a lot of time to get the answer. Therefore, I tried to create a formula.

I discovered that when I do this xy / z, I get an approximate answer for large numbers while most of the time I get same answer for small numbers.

For example: x = 70001, y = 6022, z = 316

xy / z = (70001)(6022)/(316) = 1334006 but the correct answer = 1333997 exact pairs

Is there another formula that gives me exact pairs?

Last edited: