CSharp · Console
// A chocolate bar is a rectangle with m x n rectangular pieces.
// Can we take out exactly k pieces of it
// by breaking the bar along a single straight line going between the pieces?
// The program should input 3 positive integer numbers m, n, k
// and print “Yes” if we can and “No” otherwise.
using System;
using System.Diagnostics;
public class Program
{
public static int InputInt(string prompt)
{
Console.Write("Enter " + prompt + ":");
return Convert.ToInt32(Console.ReadLine());
}
public static void Main(string[] args)
{
// input data
int side1 = InputInt("one side length");
int side2 = InputInt("another side length");
int nTake = InputInt("the number of pieces to remove");
Trace.Assert(side1 > 0 && side2 > 0 && nTake > 0);
// output result
if (nTake % side1 == 0 || nTake % side2 == 0 && nTake <= side1 * side2){
Console.Write("Yes");
}else{
Console.Write("No");
}
}
}