Problem #206 says:
Find the unique positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0,
where each “_” is a single digit.
The range of number to check can be narrowed down with a calculator and some common sense. Then its just a square and check procedure. Solution is in c# and requires the .Net 4.0 framework for its parallel extensions.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Parallel;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Numerics;
using System.Text.RegularExpressions;
namespace Net4Test
{
class Program
{
static object LockHandle = new object();
static long Answer = 0;
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
sw.Start();
Regex Test = new Regex(
"[1][0-9][2][0-9][3][0-9][4][0-9]" +
"[5][0-9][6][0-9][7][0-9][8][0-9][9][0-9][0]");
Parallel.For(1360000000, 1390000000, i =>
{
BigInteger biI = i;
if (Test.IsMatch((biI * biI).ToString()))
{
Answer = i;
}
});
Console.WriteLine(Answer);
sw.Stop();
Console.WriteLine(sw.Elapsed);
Console.ReadLine();
}
}
}
Link to this post!