• Trang Chủ
  • Thịnh Hành
No Result
View All Result
Mèo Pari Chia Sẻ Nhiều Sự Lựa Chọn
  • Trang Chủ
  • Thịnh Hành
No Result
View All Result
Mèo Pari Chia Sẻ Nhiều Sự Lựa Chọn
No Result
View All Result

Find the values of X and Y in the Given Equations – GeeksforGeeks

meopari by meopari
25/10/2022
in How To
0 0
0
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter
Given two numbers A     and B     . Find the values of X and Y in the equations.

  1. A = X + Y
  2. B = X xor Y

The task is to make ten a minimum as potential. If it is not possible to find any valid values for X and Y then print -1.
Examples:

Input : A = 12, B = 8
Output : X = 2, Y = 10

Input : A = 12, B = 9
Output : -1

Let ’ s take a look at some bite in X, which is peer to 1. If the respective bit in Y is peer to 0, then one can swap these two bits, frankincense reducing X and increasing Y without changing their sum and xor. We can conclude that if some moment in X is equal to 1 then the respective bit in Y is besides peer to 1. frankincense, Y = X + B. Taking into account that X + Y = X + X + B = A, one can obtain the follow rule for finding X and Y :

Reading: Find the values of X and Y in the Given Equations – GeeksforGeeks

  • X = (A – B) / 2
  • Y = X + B = (A + B) / 2

One should besides notice that if A < B or A and B have different parity bit, then the suffice doesn ’ thyroxine exist and end product is -1. If x and ( A – X ) not equal to X then the answer is besides -1.
Below is the execution of the above approach :

C++




#include using namespace std; void findValues( int a, int b) {           if ((a - b) % 2 == 1) {          cout << "-1" ;          return ;      }           cout << (a - b) / 2 << " " << (a + b) / 2; } int main() {      int a = 12, b = 8;      findValues(a, b);      return 0; }



Java




import java.io.*; class GFG {      static void findValues( int a, int b) {           if ((a - b) % 2 == 1 )      {              System.out.println ( "-1" );          return ;      }           System.out.println (((a - b) / 2 )+ " " +                              ((a + b) / 2 )); }           public static void main (String[] args)      {          int a = 12 , b = 8 ;          findValues(a, b);      } }



Python3




def findValues(a, b):           if ((a - b) % 2 = = 1 ):          print ( "-1" );          return ;           print ((a - b) / / 2 , (a + b) / / 2 );

Read more: How to Go Sugar-Free for a Week Straight Without Hating Your Life

a = 12 ; b = 8 ; findValues(a, b);



C#




using System; class GFG {          static void findValues( int a, int b) {           if ((a - b) % 2 == 1)      {              Console.Write ( "-1" );          return ;      }           Console.WriteLine(((a - b) / 2)+ " " +                          ((a + b) / 2)); } static public void Main () {      int a = 12, b = 8;      findValues(a, b); } }



PHP




function findValues( $a , $b ) {           if (( $a - $b ) % 2 == 1)      {          echo "-1" ;          return ;      }           echo ( $a - $b ) / 2, " " ,           ( $a + $b ) / 2; } $a = 12; $b = 8; findValues( $a , $b ); ?>



Javascript




RelatedPosts

How to Connect a Roku to Wi-Fi Without Remote

How to Get a Stain Out of a White Shirt

Eye Makeup For Beginners: Step-By-Step Looks You Can Easily Pull Off!!

How To Make and Sell Stickers Online in 5 Steps (2022)

How to Design a Website | 8 Easy-to-Follow Steps

Troubleshooting Your Windshield Wipers: How to Fix 5 Common Problems

How to Build a Website From Scratch (in 9 Easy Steps)

How to share your location on iPhone (and do it safely)

Stop Unwanted Robocalls and Texts

7 Amazing Ways to Clean a Stainless Steel Refrigerator



Output: 

2 10

Time Complexity : O ( 1 )
Auxiliary Space : O ( 1 )

My Personal Notes

Read more: How to Relieve Sinus Pressure: 7 Natural Home Remedies

arrow_drop_up

beginning : https://meopari.com
Category : How To
Previous Post

How to Go Sugar-Free for a Week Straight Without Hating Your Life

Next Post

How to File Self-Employment Taxes, Step by Step: Your Guide

meopari

meopari

MeoPari là một website tổng hợp nhiều sự lựa chọn với góc nhìn đa chiều từ nhiều tác giả cho bạn có cái nhìn tổng quan mọi vấn đề và kiến thức

Next Post

How to File Self-Employment Taxes, Step by Step: Your Guide

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Radiocarbon dating – Wikipedia

26/05/2023

PC World Game – Thế giới Game 2018

26/05/2023

Nằm mơ thấy đàn gà đánh con gì? – Ý nghĩa giấc mơ thấy đàn gà

26/05/2023

Dreidel – Wikipedia

25/05/2023

Mơ thấy rụng răng là điềm gì? Con số may mắn khi mơ thấy rụng răng – Vua Nệm

25/05/2023

Dodi Fayed – Wikipedia

25/05/2023

Leaders (Civ6)

25/05/2023

Khí hậu Châu Nam Cực – Wikipedia tiếng Việt

25/05/2023

Bếp Từ Brandt TI118B.Black giá rẻ nhất kèm COMBO khuyến mại lến tới 51%

25/05/2023

36 Desk Ideas Perfect for Small Spaces

25/05/2023

Phổ Biến Nhất

  • “12 Đánh Giá Về Masáž Tại Hà Nội Năm 2022: Cập Nhật Mới Nhất”

    0 shares
    Share 0 Tweet 0
  • Top 7 massage oasis láng hạ review mới nhất năm 2022

    0 shares
    Share 0 Tweet 0
  • Top 13 review massage hoa đà quy nhơn mới nhất năm 2022

    0 shares
    Share 0 Tweet 0
  • Thông Tin Tuyển Sinh Trường Cao Đẳng Kinh Tế Tài Chính Thái Nguyên 2023

    0 shares
    Share 0 Tweet 0
  • Top 5 review massage nine tây nam linh đàm mới nhất năm 2022

    0 shares
    Share 0 Tweet 0
  • Top 7 xe máy classic mới nhất năm 2022

    0 shares
    Share 0 Tweet 0
  • Top 16 stt bán xe máy mới nhất năm 2022

    0 shares
    Share 0 Tweet 0
  • Top 9 nằm mơ thấy bị chặt tay mới nhất năm 2022

    0 shares
    Share 0 Tweet 0
  • Top 10 review bác sĩ cao hữu thịnh mới nhất năm 2022

    0 shares
    Share 0 Tweet 0
  • Top 7 gojek chạy từ máy giờ đến máy giờ mới nhất năm 2022

    0 shares
    Share 0 Tweet 0
Sitemap
  • Thịnh Hành

© 2022 meopari.com

No Result
View All Result
  • Trang Chủ
  • Thịnh Hành

© 2022 meopari.com

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In