Calculate the number of 9 digits in a group, and the number of the first n digits can be divisible by N. For example, the first two digits can be divisible by 2, the first three digits can be divisible by 3... The first nine digits can be divisible by 9.

Source: Internet
Author: User
Code
Stopwatch Rochelle cc_stopwatch = new stopwatch ();
Rochelle 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; // obtain the number of unique digits.
}
}
Bool flag = false;
For (INT m = 2; m <= 9; m ++)
{
If (int32.parse (TS. substring (0, m) % m = 0) // The first n digits can be divisible by N
{
Flag = true;
}
Else
{
Flag = false;
}

If (flag = false)
{
Break;
}
}

If (FLAG)
{
Console. writeline (TS );
Break;
}
}

Rochelle cc_stopwatch.stop ();
Console. writeline ("{0}: Seconds", l_cc_stopwatch.elapsed.totalseconds );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.