Black cells in a chessboard Codechef Solution

Hello coders, today we are going to solve Black cells in a chessboard Codechef Solution.

Black cells in a chessboard Codechef Solution
Black cells in a chessboard Codechef Solution

Problem

Given nn (nn is even), determine the number of black cells in an n×nn×n chessboard.

Input Format

The only line of the input contains a single integer nn.

Output Format

Output the number of black cells in an n×nn×n chessboard.

Constraints

  • 2≤n≤1002≤n≤100
  • nn is even

Sample Input 1 

8

Sample Output 1 

32

Explanation

Black cells in a chessboard Codechef Solution

There are 3232 black cells and 3232 white cells in an 8×88×8 chessboard. So the answer is 3232.

Black cells in a chessboard CodeChef Solution in JAVA

import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		if(a%2==0)
		{
		    int b=(a*a)/2;
		    System.out.println(b);
		}
	}
}

Black cells in a chessboard CodeChef Solution in CPP

#include <iostream>
using namespace std;
int main() {
	// your code goes here
	int n, a, b;
	cin >> n;
	a = n * n;
	b = a / 2;
	cout << b;
	return 0;
}

Black cells in a chessboard CodeChef Solution in Python

n=int(input())
print((n*n)//2)

Disclaimer: The above Problem (Black cells in a chessboard ) is generated by CodeChef but the solution is provided by Chase2learn.This tutorial is only for Educational and Learning purpose.

Sharing Is Caring

Leave a Comment