Code
Stopwatch l_cc_stopWatch = new Stopwatch();
l_cc_stopWatch.Start();
Random rad = new Random();
while (true)
{
string ts = string.Empty;
while (ts.Length < 9)
{
string tmp = rad.Next(1, 10).ToString();
if (ts.IndexOf(tmp) < 0)
{
ts += tmp; //得到9位不重複數
}
}
bool flag = false;
for (int m = 2; m <= 9; m++)
{
if (Int32.Parse(ts.Substring(0, m)) % m == 0) //前n位能被n整除
{
flag = true;
}
else
{
flag = false;
}
if (flag == false)
{
break;
}
}
if (flag)
{
Console.WriteLine(ts);
break;
}
}
l_cc_stopWatch.Stop();
Console.WriteLine("{0}:seconds", l_cc_stopWatch.Elapsed.TotalSeconds);
Stopwatch l_cc_stopWatch = new Stopwatch();
l_cc_stopWatch.Start();
Random rad = new Random();
while (true)
{
string ts = string.Empty;
while (ts.Length < 9)
{
string tmp = rad.Next(1, 10).ToString();
if (ts.IndexOf(tmp) < 0)
{
ts += tmp; //得到9位不重複數
}
}
bool flag = false;
for (int m = 2; m <= 9; m++)
{
if (Int32.Parse(ts.Substring(0, m)) % m == 0) //前n位能被n整除
{
flag = true;
}
else
{
flag = false;
}
if (flag == false)
{
break;
}
}
if (flag)
{
Console.WriteLine(ts);
break;
}
}
l_cc_stopWatch.Stop();
Console.WriteLine("{0}:seconds", l_cc_stopWatch.Elapsed.TotalSeconds);