Street numbers#6278

Street numbers (Талдоо)

Two houses are on the same side of the street if their numbers are both odd or both even.

The condition for checking whether and have the same parity can be expressed as:

if~((n~is~even~and~m~is~even)~||~(n~is~odd~and~m~is~odd))

This can be simplified to:

if~((n + m)~\%~2 == 0)

Algorithm implementation

Read the input data.

scanf("%d %d",&n,&m);

If the sum of the numbers n + m is even, then and have the same parity. In this case print . Otherwise print .

if ((n + m) % 2 == 0) puts("1");
else puts("0");

Java implementation

import java.util.*;

public class Main
{
  public static void main(String []args)
  {
    Scanner con = new Scanner(System.in);
    int n = con.nextInt();
    int m = con.nextInt();

    if ((n + m) % 2 == 0) 
      System.out.println("1");
    else 
      System.out.println("0");

    con.close();
  }
}

Python implementation

Read the input data.

n, m = map(int, input().split())

If the sum of the numbers n + m is even, then and have the same parity. In this case print . Otherwise print .

if (n + m) % 2 == 0:
  print("1")
else:
  print("0")