コード例 #1
0
ファイル: Program.cs プロジェクト: balazsmolnar/Euler
        static void Calculate(PrimeCalculator calculator, List<ulong> allPrimes, List<ulong> currentPrimes, int primeIndex, ulong currentMul, ulong limit)
        {
            if (currentMul > MinFound)
                return;

            var numSquareDivisors = (ulong)currentPrimes.GroupBy(x => x).Select(x => x.Count() * 2 + 1).Prod();
            var result = (numSquareDivisors + 1) / 2;
            if (result >= limit)
            {
                if (currentMul < MinFound)
                {
                    MinFound = currentMul;
                    Console.WriteLine("{0}  {1}", currentMul, result);
                }
                return;
            }

            var newPrimes = new List<ulong>(currentPrimes);
            newPrimes.Add(allPrimes[primeIndex]);
            Calculate(calculator, allPrimes, newPrimes, primeIndex, currentMul * allPrimes[primeIndex], limit);

            newPrimes = new List<ulong>(currentPrimes);
            newPrimes.Add(allPrimes[primeIndex+1]);
            Calculate(calculator, allPrimes, newPrimes, primeIndex+1, currentMul * allPrimes[primeIndex+1], limit);
        }
コード例 #2
0
ファイル: WebUtils.cs プロジェクト: lujw/MVCQuestionOnlineGIT
        /// <summary>
        /// 从文本中提取用户集合
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static List<string> GetUsersFromTxt(string str)
        {
            List<string> lst = new List<string>();
            Regex regstr = new Regex(@"@(.*?)\s", RegexOptions.IgnoreCase);
            MatchCollection mc = regstr.Matches(str);
            foreach (Match match in mc)
            {
                lst.Add(match.Groups[1].Value);
            }
            lst = lst.GroupBy(x => x).Select(x => x.Key).ToList();

            return lst;
        }