C#
来源:互联网 发布:手机总是弹出登录网络 编辑:程序博客网 时间:2024/06/07 02:11
- // --------------------------------------------------------------------------------------------------------------------
- // <copyright file="Program.cs" company="Chimomo's Company">
- // Respect the work.
- // </copyright>
- // <summary>
- // The program.
- // </summary>
- // --------------------------------------------------------------------------------------------------------------------
- namespace CSharpLearning
- {
- using System;
- /// <summary>
- /// The program.
- /// </summary>
- public static class Program
- {
- /// <summary>
- /// The main.
- /// </summary>
- /// <param name="args">
- /// The args.
- /// </param>
- public static void Main(string[] args)
- {
- string fac100 = Factorial(100).ToString("F0");
- Console.WriteLine("The factorial of 100 is : {0}", fac100);
- for (int i = 0; i <= fac100.Length - 4; i++)
- {
- string substr = fac100.Substring(i, 4);
- if (CheckPrime(Convert.ToInt32(substr)))
- {
- Console.WriteLine("The expected result found and it is : " + substr);
- return;
- }
- }
- Console.WriteLine("No result as expected!!");
- }
- /// <summary>
- /// The factorial.
- /// </summary>
- /// <param name="n">
- /// The n.
- /// </param>
- /// <returns>
- /// The <see cref="double"/>.
- /// </returns>
- public static double Factorial(int n)
- {
- double result = 1;
- for (int i = 1; i <= n; i++)
- {
- result *= i;
- }
- return result;
- }
- /// <summary>
- /// The check prime.
- /// </summary>
- /// <param name="n">
- /// The n.
- /// </param>
- /// <returns>
- /// The <see cref="bool"/>.
- /// </returns>
- public static bool CheckPrime(int n)
- {
- if (n == 1 || n == 2)
- {
- return true;
- }
- int squareRoot = Convert.ToInt32(Math.Sqrt(n));
- for (int i = squareRoot; i > 1; i--)
- {
- if (n % i == 0)
- {
- return false;
- }
- }
- return true;
- }
- }
- }
- // Output:
- /*
- The factorial of 100 is : 93326215443944100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- The expected result found and it is : 2621
- */
- 转自:http://blog.csdn.net/troubleshooter/article/details/5506027
阅读全文
0 0
- C#
- C#
- C#
- C#
- C#
- C#
- C#
- C#
- C#
- C#
- C#
- c#
- c#
- C#
- C#
- C#
- c#
- C#
- Java实现参数解析
- CSS常见布局解决方案
- tomcat集群 memcache共享session
- Pos终端中的主密钥、工作密钥、pin密钥、mac密钥
- Material-UI FontIcon组件使用
- C#
- django 重新回忆
- 每天laravel-简单的运行流程
- SpringMvc自定义消息转换器
- h5开发中常见的问题汇总
- QWebEngineView支持XP
- 工业自动化的发展趋势
- 如何清理myeclipse自带的tomcat的缓存
- Hadoop基础教程-第7章 MapReduce进阶(7.1 MapReduce过程)(草稿)