Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Find the integers which squares sum gives the prime numbers of the form (4k + 1).
//Rextester.Program.Main is the entry point for your code. Don't change it. //Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354) using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { Console.WriteLine("Find (X, Y) such that X^2 + Y^2 = P, where P is a prime number of form (4k + 1)."); for (int i = 5; i <= 2017; i++) { if (i % 4 == 1 && IsPrime(i)) { Console.WriteLine($"(4k + 1) number: {i}. (X, Y): {GetSquares(i)}"); } } } public static Tuple<int, int> GetSquares(int target) { for (int i = 0; i <= target; i++) { for (int j = 0; j <= target; j++) { var x2 = i * i; var y2 = j * j; if (x2 + y2 == target) return new Tuple<int, int>(i, j); } } return new Tuple<int, int>(-1, -1); } public static bool IsPrime(int target) { for (int i = 2; i <= target / 2 + 1; i++) if (target % i == 0) return false; return true; } } }
run
|
edit
|
history
|
help
0
Delegate-ModifyObject
out parameters
My_Response
Plt-D v.0.8.5
delete_xml_empty_tags
Conditional linq operators
Test Stopwatch
Testing 004
eryjuyhtgrfesdsadcfg
itervativeFact