Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
4 squares theorem
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Diagnostics; using System.Threading; using System.Threading.Tasks; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester{ public class Program{ public static void Main(string[] args){ int upto = 2000; float circles = 0; string[] erg = new string[upto+1]; Stopwatch sw = new Stopwatch(); sw.Start(); List<int> test = new List<int>(); for(int i = 1;i<=upto;i++) test.Add(i); Task[] Tasks = new Task[Environment.ProcessorCount]; for(int t = 0;t<Tasks.Length;t++) Tasks[t] = new Task(()=> { while(test.Count != 0){ int n,a,b,c,d,na,nb,nc,nd,tmp = 0; bool solved = false; n = test[0]; test.Remove(n); for(a = 0 , na = n ;a < na && !solved;a++){ for(b = 0 , nb=na-a*a;b < nb&& !solved;b++){ for(c = 0 , nc = nb -b*b;c < nc&& !solved;c++) { tmp++; nd = nc -c*c; d = (int)Math.Sqrt(nd); if(d*d == nd){ solved = true; circles += tmp; erg[n-1] = n + " = " + a +"^2 + "+b+"^2 + "+c+"^2 + "+d+"^2 Circles: "+tmp ; } } } } }}); foreach(Task item in Tasks) item.Start(); Task.WaitAll(Tasks); sw.Stop(); erg[erg.Length-1] = circles +" Cricles in "+sw.Elapsed+" seconds"; foreach(string item in erg) Console.WriteLine(item); } } }
run
|
edit
|
history
|
help
0
JagArray
circleTest
Full text search using Linqdb
TEst
NeedFirst
tester of xpath
Simple Parallel.For example
Generics
List of Lists example
ReverseArrayC#