is there a way to check N numbers if they are all odd or even without using mod function %??? ,i can only use - + * functions.
check if n numbers are all odd or even using - + * operations only
66 Views Asked by reeena11 At
1
There are 1 best solutions below
Related Questions in MATH
- How to restrict vpasolve() to only integer solutions (MATLAB)
- Need clarification on VHDL expressions involving std_logic_vector, unsigned and literals, unsure about compiler interpretation
- What is the algorithm behind math.gcd and why it is faster Euclidean algorithm?
- How to throw a charged particle in a electric vector field?
- Issues with a rotation gizmo and sign flips when converting back to euler angles
- Solving the area of a 2 dimensional shape
- WorldToScreen function
- Algorithm to find neighbours of point by distance with no repeats
- Detecting Circles and Ellipses from Point Arrays in Java
- three parameter log normal distribution
- Bound for product of matrices
- Javascript animation taking incorrect amount of time to reach desired location
- Converting Math.js-like Expressions to Runnable Python Code
- Looking for a standard mathematical function that returns 0 if x = 0 and a constant k when x <> 0
- Partitions in co-lexicographic order (PARI/GP algorithm without recursion)
Related Questions in SUM
- Find the sum of the numbers in the sequence
- how to find sum of input value in javascript
- Multiple child processes accessing the same vector
- finding sum of prefilled fields with jquery
- Sum multiple items in 2D array based on condition (javascript)
- How do I take 2 tabs from a google sheet and combine based on the 1st column but also sum the 2nd column in Google Sheets?
- R. Sum over rows
- Dates in R: Counting Instances and Number of Days
- Summing across multiple tables and location of subquery
- How to Sum Values by Column 'Date' After Averaging by Column 'Site'?
- sum in multiple sheets with corresponding values in excel
- Power BI Dax SUM
- Calculating the sum of differences between two columns in Laravel
- Getting the sums for each desired item in a list
- Create a new table with the percentage quantity amount of individual counterparties compared to the total quantity
Related Questions in OPERATIONS
- How to make SUM(A+B) without defining the row number?
- Magento2 - Bulk Operations Consumer Issue
- numpy column wise division to the power of n
- quadratic equality constraint: Julia+Jump+Gurobi
- batch: combine string operations
- MongoDB $substr from index to index
- Order of operators on subtract
- Enterprise Architect Operation Pre/Post-Conditions
- Combining user specific TensorFlow models into one, based on the userId
- check if n numbers are all odd or even using - + * operations only
- IOperable interface .net
- Conditional operation based on column label in pandas dataframe
- Basic operations with arrays
- Creating subsets of data using bash and measuring comparisons in java programs
- BufferedWriter and FileWriter writing strange character instead of number to text file Java
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
So you can use addition, subtraction, multiplication, and comparisons. I'll also assume you can define functions, and your goal is to define two functions:
evenListfunction takes a list of numbers and returns true iff (if-and-only-if) the list contains only even numbers.oddListfunction takes a list of numbers and returns true iff the list contains only odd numbers.First let's define an
evenfunction that takes a single number and returns true iff the input is even:We can define an
oddfunction in terms ofeven:We could then just define
evenListrecursively too:(I'm using
x : xsto mean a list whose first element isxand whose remainder isxs. I'm usingnilto mean an empty list.)But maybe you're not allow to use a boolean
&operator. What can we do instead?Consider multiplying two numbers, i and j. What parity is the result, based on the parity of i and j? (Parity means oddness or evenness.)
even(i) & even(j) -> even(i*j)even(i) & odd(j) -> even(i*j)odd(i) & even(j) -> even(i*j)odd(i) & odd(j) -> odd(i*j)(I'm using
->to means “implies”.) In other words, i*j is odd iff i is odd and j is odd.So, if you multiply all of your input numbers together and the product is odd, then all of the inputs are odd. So we'll define a
productfunction:And then we can define
oddListlike this:But how to know if all of the inputs are even? Even a single even input makes the product even.
The trick is to reverse the parity of all the inputs, and then reverse the parity of the result. You can reverse the parity by adding or subtracting one. Let i1 = i + 1 and j1 = j + 1. Then:
even(i) & even(j) -> odd(i1) & odd(j1) -> odd(i1 * j1) -> even(i1 * j1 + 1)even(i) & odd(j) -> odd(i1) & even(j1) -> even(i1 * j1) -> odd(i1 * j1 + 1)odd(i) & even(j) -> even(i1) & odd(j1) -> even(i1 * j1) -> odd(i1 * j1 + 1)odd(i) & odd(j) -> even(i1) & even(j1) -> even(i1 * j1) -> odd(i1 * j1 + 1)In other words, (i+1) * (j+1) + 1 is even if and only if i is even and j is even.
So, let's define a
product1function that returns the product of all of its inputs, each incremented by 1 first:Then we can define
evenListlike this: