Event Pair Sum (EVENPSUM)Solution — Codechef December Long Challenge

Anubhav Mishra
1 min readDec 14, 2020

--

Problem Statement

You are given two positive integers A and B. Find the number of pairs of positive integers (X,Y) such that 1≤X≤A, 1≤Y≤B and X+Y is even.

Input

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • The first and only line of each test case contains two space-separated integers A and B.

Output

For each test case, print a single line containing one integer ― the number of valid pairs.

Constraints

  • 1≤T≤1,000
  • 1≤A,B≤109

Subtasks

Subtask #1 (10 points): A,B≤10

Subtask #2 (10 points): A,B≤1,000

Subtask #3 (80 points): original constraints

Example Input

4
1 1
2 3
4 6
8 9

Example Output

1
3
12
36

Code ( Solution )

The code has been implemented in Java.

import java.util.*;import java.lang.*;import java.io.*;class Codechef{public static void main (String[] args) throws java.lang.Exception{// your code goes hereScanner sc = new Scanner (System.in);int t = sc.nextInt();long a,b=0;while(t-- > 0){long o1,o2,e1,e2 =0;  a = sc.nextInt();  b = sc.nextInt();  if(a%2==0){     e1 = a/2;     o1 = a/2;}else{  o1 = a/2 +1;  e1 = a/2;}if(b%2==0){  e2 = b/2;  o2 = b/2;}else{  o2 = b/2+1;  e2 = b/2;   }System.out.println((o1*o2)+(e1*e2));  } }}

Hope you would have liked the article. Please give a clap to this article and follow me for more future programming related blogs.

Referenced Question Link

https://www.codechef.com/DEC20B/problems/EVENPSUM

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Anubhav Mishra
Anubhav Mishra

Written by Anubhav Mishra

Software Engineer , Having my degree B.Tech in Information Technology from BVCOE, New Delhi. Love new Technologies. Electronic Dance Music is love.

Responses (1)

Write a response