even-odd-5

We have the following matrix 
1 0 0 0 0 0 ...
2 2 0 0 0 0 ...
3 3 3 0 0 0 ...
4 4 4 4 0 0 ... 
5 5 5 5 5 0 ... 
6 6 6 6 6 6 ...
and so on ... 

The matrix is created as follows, first row contains one 1 and rest 0's, second row contains 2 twos and rest zeros, third row contains 3 threes and so on.

Given R and C, calculate the count of even and odd numbers in sub matrix [R,C] .
0 is neither odd nor even and 1 based indexing is used i.e. matrix [1,1]=1 

Input:
First line contains number of test cases T.Each test case contains two integers R and C.

Output
For each test case print count of even and odd numbers in sub matrix [R,C].

Constraints:
1 ≤ T ≤ 100000  
1 ≤ R ≤ 100000 
1 ≤ C ≤ 100000  

SAMPLE INPUT
3
2 3
6 7
10 10

SAMPLE OUTPUT
2 1
12 9
30 25

Difficulty: EASY
Tags: Mathematics

Ad-hoc

Starter code:

Solutions:
T=eval(input())
while(T):
	T-=1
	[r,c]=list(map(int,input().split()))
	if(r<=c):
		if(r%2):
			odd_ans=(((r+1)/2)*(1+r))/2;
			even_ans=((r/2)*(1+r))/2;
		else:
			odd_ans=((r/2)*(r))/2;
			even_ans=((r/2)*(2+r))/2;
	else:
		if(c%2):
			odd_ans=(((c+1)/2)*(1+c))/2;
			even_ans=((c/2)*(1+c))/2;
				
			if((r-c)%2):
				even_ans+=(((r-c+1)/2)*c);
				odd_ans+=(((r-c)/2)*c);
			else:
				even_ans+=(((r-c)/2)*c);
				odd_ans+=(((r-c)/2)*c);
		else:
			odd_ans=((c/2)*(c))/2;
			even_ans=((c/2)*(2+c))/2;
				
			if((r-c)%2):
				even_ans+=(((r-c)/2)*c);
				odd_ans+=(((r-c+1)/2)*c);
				
			else:
				even_ans+=(((r-c)/2)*c);
				odd_ans+=(((r-c)/2)*c);
				
	print(even_ans,odd_ans)


tc = int(input())
if 1<=tc<=100000:
	for i in range(tc):
		r,c = input().split()
		r,c = int(r),int(c)
		if 1<=r<=100000 and 1<=c<=100000:
			if r == 1:
				print(0,1)
				continue
			if c == 1:
				print(c/2,(c/2)+1)
				continue
			even,odd = 0,0
			if r<=c:
				row = r/2
				even =  2*row*(row+1)/2
				odd = r*(r+1)/2 - even
			else:
				row = c/2
				even =  2*row*(row+1)/2
				odd = c*(c+1)/2 - even
				n = r-c
				if n%2 == 0:
					even = even + (c*(n/2))
					odd = odd + (c*(n/2))
				if n%2 and r%2:
					even = even + ((n/2)*c)
					odd = odd + ((n- (n/2))*c)
				if n%2 and not(r%2):
					odd = odd + ((n/2)*c)
					even = even + ((n- (n/2))*c)
			
			print(even,odd)


import sys
input()
for val in sys.stdin:
	r=int(val.split()[0])
	c=int(val.split()[1])
	if r==1 :
		print(0,1)
	elif r%2 :
		if c>=r:
			print(((r-1)/2 +1)*(r-1)/2,((r+1)/2)**2)
		else:
			if not c%2 :
				y=r-c
				e=((r-1)/2 +1)*(r-1)/2
				o=((r+1)/2)**2
				e=e-((y-1)/2 +1)*(y-1)/2
				o=o-((y+1)/2)**2
				print(e,o)
			else :
				y=r-c
				e=((r-1)/2 +1)*(r-1)/2
				o=((r+1)/2)**2
				e=e-(y/2)**2
				o=o-(y/2+1)*(y/2)
				print(e,o)
	else:
		if c>=r:
			print((r/2+1)*(r/2),(r/2)**2)
		else:
			if not c%2:
				y=r-c
				e=(r/2+1)*(r/2)
				o=(r/2)**2
				o=o-(y/2)**2
				e=e-(y/2+1)*(y/2)
				print(e,o)
			else:
				y=r-c
				e=(r/2+1)*(r/2)
				o=(r/2)**2
				e=e-((y+1)/2)**2
				o=o-((y-1)/2+1)*((y-1)/2)
				print(e,o)

				
				
				
				 
		


#! /usr/bin/python

t = int(input())

for i  in range(t):
	s = input()
	l = s.split()
	r = int(l[0])
	c = int(l[1])
	etotal = 0
	ototal = 0
	tmp1 = 0
	if (r > c):
		tmp1 = c
	else:
		tmp1 = r
	n1 = tmp1 / 2
	n2 = (tmp1 + 1)/2
	etotal = n1 * ((4 + (n1 - 1)*2)/2)
	ototal = n2 * ((2 + (n2 - 1)*2)/2)

	tmp2 = r - c
	if (tmp2 > 0):
		if (r % 2 != 0):
			n1 = tmp2/2
			n2 = (tmp2 + 1)/2
		else:
			n1 = (tmp2 + 1) / 2
			n2 = tmp2 / 2
		etotal += n1 * c
		ototal += n2 * c


	print(etotal,ototal)







t = eval(input())
while(t):
	rc = input().split()
	r = int(rc[0])
	c = int(rc[1])
	if(c>=r):
		noofodd=r
		if(r%2==0):
			noofodd-=1
		noofodd=(noofodd+1)/2
		noofodd*=noofodd
		noofeven=r
		if(r%2==1):
			noofeven-=1
		noofeven=(noofeven)/2
		noofeven=noofeven*(noofeven+1)
		print(noofeven,noofodd)
	else:
		R=r
		r=c
		noofodd=r
		if(r%2==0):
			noofodd-=1
		noofodd=(noofodd+1)/2
		noofodd*=noofodd
		noofeven=r
		if(r%2==1):
			noofeven-=1
		noofeven=(noofeven)/2
		noofeven=noofeven*(noofeven+1)
		leftover=(R-r)*(c)
		if((r+1)&1==1):
			odd=(((R-r)+1)/2)*c
			even=leftover-odd
		else:
			even=((R-r+1)/2)*c
			odd=leftover-even
		print(noofeven+even,noofodd+odd)
	t-=1