Skip to content

Instantly share code, notes, and snippets.

@unilecs
Last active March 5, 2018 08:01
Show Gist options
  • Save unilecs/b9188b8404f105bf9ba4e6f369a9235d to your computer and use it in GitHub Desktop.
Save unilecs/b9188b8404f105bf9ba4e6f369a9235d to your computer and use it in GitHub Desktop.
Задача 75: Тумблеры
using System;
public class Program
{
public static int GetTumblerStatus(int n)
{
if (n <= 0)
{
throw new Exception("N should be greater than 0!");
}
int sqrt = (int)Math.Sqrt(n);
// Если N - полный квадрат, выводим 1, иначе 0.
return sqrt * sqrt == n ? 1 : 0;
}
public static void Main()
{
Console.WriteLine("UniLecs");
Console.WriteLine(string.Format("Answer = {0}", GetTumblerStatus(1))); // 1
Console.WriteLine(string.Format("Answer = {0}", GetTumblerStatus(5))); // 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment