p is the number of elements (m , n) such that 6m+9n is a multiple of 5.
6m+9n=0 (mod 5)
6 = 1 (mod 5)
6m=1m=1 (mod 5)
9 = 4 (mod 5)
9n=4n (mod 5)
1+4n=0 (mod 5)
Now, 41=4 (mod 5)
42=1 (mod 5)
43=4 (mod 5)
44=1 (mod 5)
Now, we will get a remainder of 1 if we divide 1 by 5 (for any value of m) and a remainder of either 1 or 4 from 4n if n is even or odd, respectively.
It is given that 6m+9n is a multiple of 5.
It means that the remainder that we get from 6m+9n must be a multiple of 5.
So, we need the remainder of 4 from 4n.
Hence, n will be odd.
m can take any value from 1 to 50 and n can only take odd numbers.
So, the number of elements of (m , n) for which 6m+9n must be a multiple of 5 is (50×25)=1250
p = 1250
Now, q is the number of elements (m , n) such that (m+n) is a square of a prime number.
1≤(m , n)≤50
2≤(m + n)≤100
Square of prime numbers which is less than 100 = 22, 32, 52, 72
So, (m+n) = 4, 9, 25 and 49
For 1≤(m , n)≤50, if (m+n)≤51, there will be a total of (m+n−1) elements.
For (m+n) = 4, (m , n) = (1,3) , (2,2) , (3,1) i.e. 3 combinations.
For (m+n) = 9, (m , n) will have 8 combinations.
For (m+n) = 25, (m , n) will have 24 combinations.
For (m+n) = 49, (m , n) will have 48 combinations.
Total combinations of (m+n) = (3+8+24+48) = 83
q = 83
So, (p+q) = 1250+83 = 1333
Hence, the sum of the values of p and q is 1333.