Last active
February 28, 2018 20:33
-
-
Save bashmohandes/0c1a9f1be213e9a0712530039ff0d932 to your computer and use it in GitHub Desktop.
Video coding session: https://youtu.be/HU_lpuK1-0E
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; | |
using System.Linq; | |
using System.Collections.Generic; | |
public class SumSquaredDivisors | |
{ | |
public static string listSquared(long m, long n) | |
{ | |
var result = new List<string>(); | |
for (var i = m; i <= n; i++) | |
{ | |
var sumOfSquaredDivs = SumSquaredDivisors.Divisors(i).Select(d => d * d).Sum(); | |
if (IsSquared(sumOfSquaredDivs)) | |
{ | |
result.Add($"[{i}, {sumOfSquaredDivs}]"); | |
} | |
} | |
return "[" + String.Join(", ", result) + "]"; | |
} | |
private static IEnumerable<long> Divisors(long input) | |
{ | |
for (var i = 1; i <= input; i++) | |
{ | |
if (input % i == 0) | |
{ | |
yield return i; | |
} | |
} | |
} | |
private static bool IsSquared(long number) | |
{ | |
var sqrt = Math.Sqrt(number); | |
return ((int)sqrt * (int)sqrt) == number; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
بالجافا سكريب
https://github.com/AhmedElMetwally/javascript/blob/master/Integers:%20Recreation%20One.js