Algorithm Analysis
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 is even, then and have the same parity.
If the sum of the numbers is odd, then and have different parities.
Algorithm Implementation
Read the input data.
scanf("%d %d", &n, &m);
If the sum of the numbers is even, then and have the same parity. In this case, print 1. Otherwise, print 0.
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 is even, then and have the same parity. In this case, print 1. Otherwise, print 0.
if (n + m) % 2 == 0: print("1") else: print("0")