Hello Programmers In this post, you will know how to solve the Odd Pairs Codechef Solution. The Problem Code is ODDPAIRS.
One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.
Problem
Given an integer NN, determine the number of pairs (A, B) such that:
- 1 ≤ A, B ≤ N;
- A + B is odd.
Input Format
- The first line of input will contain a single integer TT, denoting the number of test cases.
- Each test case consists of a single integer NN.
Output Format
For each test case, output the number of required pairs.
Constraints
Sample 1
Input
5 1 2 3 100 199
Output
0
2
4
5000
19800
LinkedIn Skill Assessment Answers
Coursera Quiz Answers
Explanation:
Test case 1: There are no pairs satisfying the given conditions.
Test case 2: The pairs satisfying both conditions are: (1,2) and (2,1).
Test case 3: The pairs satisfying both conditions are: (1,2),(2,1),(2,3), and (3,2).
Odd Pairs Codechef Solutions in CPP
#include <iostream> using namespace std; int main() { int t,i; cin>>t; while(t--) { long int n,o=0,e=0,res; cin>>n; o=(n+1)/2; e=n/2; res=2*o*e; cout<<res<<"\n"; } return 0; }
Odd Pairs Codechef Solutions in JAVA
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t>0){ long n = sc.nextLong(); System.out.println((n/2)*(n-(n/2))*2); t--; } } }
Odd Pairs Codechef Solutions in Python
# cook your dish here #odd pairs 2 (1,2) (2,1) I.E N^2//2 METHODS ARE POSSIBLE n = int(input()) while(n>0): a = int(input()) print((a**2)//2) n = n-1
Disclaimer: The above Problem (Odd Pairs) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purpose.
Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.