Two houses are on the same side of the street if their numbers are both odd or both even.
If the sum of the numbers n + m is even, then and have the same parity.
If the sum of the numbers n + m is odd, then and have different parities.
The condition for checking whether and have the same parity can be expressed as:
This can be simplified to:
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")