1550个...需要.Net 4.0支持...
System.Numerics.BigInteger Factorial(System.Numerics.BigInteger i)
{
System.Numerics.BigInteger result = 1;
while (true)
{
if (i < 2)
return result; result *= i;
i--;
}
}
Console.WriteLine(Factorial(3000).ToString().Where(c => c == '0').Count());
System.Numerics.BigInteger Factorial(System.Numerics.BigInteger i)
{
System.Numerics.BigInteger result = 1;
while (true)
{
if (i < 2)
return result; result *= i;
i--;
}
}
Console.WriteLine(Factorial(3000).ToString().Where(c => c == '0').Count());
解决方案 »
- 用C#写的一个最简单最简单的代理服务器,求指教
- winform 窗口加载时闪动问题
- c#数据库连接的问题
- SOS!!!关于进程间通讯的问题--FindWindow,高手得出手啊,在线等
- myString.Substring(0, 3);我要中文算2个字,英文算一个字,怎么做?
- 合并DataSet 所有列
- VS.NET2003中的属性或解决方案资源管理器等一系列窗口,按小按钮后可以固定位置,或当鼠标over时才伸展出来,没有over时就自动缩加隐藏,
- 调用静态方法的问题
- 请问:如果客户买了一个如用友速达,金蝶,管家婆进销存,财务,ER之类的商业软件.软件公司或代理商要不要给客户软件的源代码??
- IP问题,请高手不吝赐教!
- 两个Grid行左右移动,但是出现刷新问题,再次移动的时候原来的行没了?
- C#工具条的button怎样给他添加快捷键?
但是没找到一个合适的类型来存储结果:
int[] iii = Enumerable.Range(1, 3000).ToArray();
var query=iii.Aggregate((a, b) => a * b);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;namespace ConsoleLinq
{
public class Program
{
public static void Main(string[] args)
{
int n, i, j, x, s;
string qq;//用于控制循环的退出
int[] a = new int[10000];//存放求出来的数
Console.Write("是否退出,退出请输入q后回车,不退出请随意输入一个字符");
while (true)
{
int k;
//控制是否退出循环
qq = Console.ReadLine();
if (qq == "q") break;
//读取n
Console.Write("求n!的值,最大可求3200!,请输入一个数字:");
n = int.Parse(Console.ReadLine());
a[0] = 1;
for (i = 1; i < 10000; i++) a[i] = 0;//给数组赋初始值
for (i = 1; i <= n; i++)
{
x = 0;
s = 0;
for (j = 0; j < 10000; j++)
{
x = i * a[j] + s;//乘积加上进位
a[j] = x % 10;//每个数组单项等于上面算得的数除以10的余数
s = x / 10;//求出进位用于下次相加
}
}
for (i = 9999; i >= 0; i--) if (a[i] > 0) break;
Console.WriteLine("结果:{0}!共有{1}位数", n, i + 1);//打印出结果共有几位
Console.Write("{0}!=", n);
int zeroCount = 0;
for (j = i; j >= 0; j--)
{
if (a[j] == 0)
{
zeroCount++;
}
Console.Write(a[j]);//打印出结果
}
Console.WriteLine("结果中0的个数"+ zeroCount);
}
}
}
}
void Main()
{
int n =10;
int[] iii = Enumerable.Range(1,n).ToArray();
var query=iii.Aggregate((a, b) => a * b);
Console.WriteLine(n+" 的阶乘是:"+query);
query=query.ToString().ToCharArray().Count(m => m.ToString().Equals("0"));
Console.WriteLine("\r\n"+n+" 的阶乘中0的个数是:"+query);
}
/*
10 的阶乘是:362880010 的阶乘中0的个数是:2*/
using System;namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int upper = 3000;
int zeroCount = 0; while (upper != 0)
zeroCount += upper /= 5; Console.WriteLine(zeroCount);
}
}
}
#include <stdlib.h>
#define MAX_NUM 3000
#define MOD_OF_ARY 10000int main(){
static int ary[MAX_NUM] = { 1 };
int i, j;
int width; /*---表示结果的"宽度"---*/
int current_num; /*--- 当前数字 ---*/
/*--- 从大到小进行阶乘计算 ---*/
for( width = 0 , current_num = MAX_NUM ; current_num > 1; current_num-- ){
/*--- 对每一个‘分段’进行运算 ---*/
for( i = j = 0; i <= width; i++ ){
/*--- 当前运算的‘有效数值’ ---*/
ary[i] = ( (j += ary[i] * current_num) ) % MOD_OF_ARY;
/*--- 当前运算的‘进位数值’ ---*/
j /= MOD_OF_ARY;
} if ( ary[i] = j ){ /*如果有进位,则索引向前推进*/
width++;
}
} printf ( "%d", ary[width] ); /*--- 将求的数值输出 ---*/
for( j = width - 1; j >= 0; j-- ){
printf( "%04d", ary[j] );/*--- 这里的6跟MOD_OF_ARY的位数有关 ---*/
} printf ("\n");
//system ("pause");
}================================
int num=0;
for(int i=0;i<3000;i++)
{
int j=i;
while(j%5==0)
{
num++;
j=j/5;
}
}
return numl;
<html>
<head>
<script type="text/javascript">
function jisuan(ct)
{
num=0;
for(i=1;i<ct;i++)
{
j=i;
while(j%5==0)
{
num++;
j=j/5;
}
}
alert(num);
}
</script>
</head>
<body>
<script>
jisuan(3000);
</script>
</body>
</html>结果是745
for(i=1;i<ct;i++)改为for(i=1;i<=ct;i++)
这么强大啊,呵呵,测试测试哈
小心搞崩机了