用java做1000的阶乘 代码

来源:百度知道 编辑:UC知道 时间:2024/06/06 13:01:45
不能用biginteger

2568位 ,结果不打上来,你自己看吧
------------------
int[] res = new int[3000];
final int limit = 1000;

res[1] = 1; //0405
int max_now = 1;

for(int step = 1; step <= limit;step++)
{
int temp = 0;
int now = max_now; //40320
int zero;
for(zero = 1; zero <=now;zero++) //PASS掉末尾的零.
{
if(res[zero] != 0)
break;
}

for(int carry = zero-1;carry <= now;carry++)
{
res[carry] *= step;
res[carry] += temp;
temp = 0;
if(res[carry] >= 10)
{
int carry_temp = carry;
temp = res[carry];
if(carry_temp <= max_now)