• 大数


    大数运算
     1 using System;
     2 using System.Numerics;
     3 
     4 namespace ConsoleApplication1
     5 {
     6     class Program
     7     {
     8         static void Main(string[] args)
     9         {
    10             BigInteger tmp = BigInteger.Zero;
    11             System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
    12             sw.Start();
    13             //tmp = Factorial(15100);
    14             ForResult(99999);
    15             sw.Stop();
    16             Console.WriteLine(tmp.ToString().Length.ToString()+"   "+sw.Elapsed.ToString());
    17 
    18         }
    19         
    20         /// <summary>
    21         /// 使用递归
    22         /// </summary>
    23         /// <param name="i"></param>
    24         /// <returns></returns>
    25         public static System.Numerics.BigInteger Factorial(BigInteger i)
    26         {
    27             if (i < 0)
    28             {
    29                 return BigInteger.Zero;
    30             }
    31             else if(0==i)
    32             {
    33                 return 1;
    34             }
    35             else
    36                 return Factorial(i - 1* i;
    37         }
    38 
    39         public static BigInteger ForResult(BigInteger i)
    40         {
    41             BigInteger tmp=1;
    42             do
    43             {
    44                 tmp *= i;
    45                 i--;
    46             }
    47             while (i > 0);
    48             return tmp;
    49         }
    50 
    51     }
    52 }
    53 
  • 相关阅读:
    JS 中 new 操作符
    js清除浏览器缓存的几种方法
    一个自定义分享按钮
    解决windows下nginx中文文件名乱码
    sublime text 3 添加 javascript 代码片段 ( snippet )
    transition动画最简使用方式
    hammerjs jquery的选项使用方法,以给swipe设置threshold和velocity为例
    sublime text 3 的emmet 添加自定义 html 片段
    解决 placeholder 垂直不居中,偏上的问题
    Sublime Text 3 配置 sass
  • 原文地址:https://www.cnblogs.com/muyoushui/p/1716507.html
Copyright © 2020-2023  润新知