Pythagorean Triples Using C#

What is Pythagorean triples?

Pythagorean triples are a2+b2 = c2 where a, b and c are the three positive integers.

Pythagorean theorem

It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.

For example, triples (3, 4, 5), (5, 12, 13), and (6, 8, 10) are Pythagorean triples.

Input Format

The only line of the input contains a single integer n, the length of some side of a right triangle.

Sample TestCase 1

Input
3
Output
4 5

Check the below code for the optimal solution.

using System;
using System.Collections.Generic;
using System.IO;

class CandidateCode {
    static void Main(String[] args) {
        var m = Convert.ToInt32(Console.ReadLine());
        decimal b, c = 0;
        if ((m % 2) != 0)
        {
            b = Math.Ceiling(Convert.ToDecimal(((m * m) / 2) - 0.5));
            c = Math.Ceiling(Convert.ToDecimal(((m * m) / 2) + 0.5));
        }
        else
        {
            m = m / 2;
            b = Math.Ceiling(Convert.ToDecimal((m * m) - 1));
            c = Math.Ceiling(Convert.ToDecimal((m * m) + 1));
        }
        Console.WriteLine(b + " " + c);
    }
}

Memory and time utilization detail as below,

Pythagorean Triples Using c#