Good Pairs
Practice
4.7 (3 votes)
Basics of implementation
Math
Basic math
Basic programming
Problem
91% Success 340 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given an integer \(N\).

A pair \((x,y)\) is considered good if \(x\) is odd and \(y\) is even.

Task

Your task is to count the number of good pairs among N's digits.

Note: 

  • You have to count duplicate pairs forming as well. View the sample explanation section for more clarification.

Example

Assumption:

\(N\) = 1224

Approach:

The odd numbers amongst N's digits are [1] and even digits are [2,2,4]. The total pairs that can be formed are (1,2), (1,2) and (1,4). Thus, the answer is 3. 

Function description

Complete the function solve provided in the editor. This function takes the following one parameter and returns the required answer:

\(N\): the integer amongst whose digits you have to count the good pairs.

Input format

Note: This is the input format that you must use to provide custom input (available above the Compile and Test button).

The first line contains \(T\) denoting the number of test cases. \(T\) also specifies the number of times you have to run the solve function on a different set of inputs.
For each test case:
The first line contains the integer \(N\).

Output format
For each test case, print the answer in a new line. 

Constraints

\(1 \leq T \leq 10\)
\(1 \leq N \leq 10^{16}\)

Code snippets (also called starter code/boilerplate code)

This question has code snippets for C, CPP, Java, and Python.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:10
17 votes
Tags:
MathematicsBasic MathMath
Points:10
1 votes
Tags:
Very-Easy
Points:10
2 votes
Tags:
Basic ProgrammingBasic MathMathImplementationBasics of ImplementationBasics of Input/Output