Exactly one condition out of two#8891

Exactly one condition out of two (Editorial)

The variable will be used to count the number of satisfied conditions. Initially, it is assigned a value of .

If flag = 1, exactly one condition is satisfied, so print "YES". Otherwise, print "NO".

Example

Let n = 22. The number is even. It is not negative and divisible by . Thus, only one condition is satisfied. The answer is "YES".

Algorithm implementation

Read the input number .

scanf("%d", &n);

Check two conditions. If a condition is satisfied, increment the value of the variable by .

flag = 0;
if (n % 2 == 0) flag++;
if (n < 0 && n % 3 == 0) flag++;

Based on the value of , print the result.

if (flag == 1) puts("YES");
else puts("NO");

Python implementation

Read the input number .

n = int(input())

Check two conditions. If a condition is satisfied, increment the value of the variable by .

flag = 0
if n % 2 == 0:
  flag += 1
if n < 0 and n % 3 == 0:
  flag += 1

Based on the value of , print the result.

if flag == 1:
  print("YES")
else:
  print("NO")