-
-
Save unilecs/b9188b8404f105bf9ba4e6f369a9235d to your computer and use it in GitHub Desktop.
Задача 75: Тумблеры
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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