寻找阶乘的平方根 [英] finding square root of factorial

查看:127
本文介绍了寻找阶乘的平方根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我已经找到2000的阶乘.那么,如果我必须找出大阶乘的平方根,那么该怎么办?我可以认为它可能是牛顿拉夫森方法.

suppose i have found out the factorial of 2000. then if i have to find out the square root of the large factorial..then what to do?? can some one plzz frwd the algo for it..i think it might be newton raphson method.

推荐答案

如果您知道方法名,那么为什么不尝试
If you know the method name then why not try this[^] to start with?


如果您知道您将采用阶乘函数结果的平方根,只需实现一个直接计算阶乘的平方根的函数即可:

因为factorial(n)是2到n的整数的乘积
阶乘(n)的平方根是从2到n的每个整数的平方根的乘积
或更有效:

返回Math.Pow(factorial(n), 0.5)(假设factorial(n)是类型double)

如果您的factorial(n)返回BigInteger,请使用Math.Exp(Math.BigInteger(factorial(n))/2.0)

我忘记了您指出您使用的语言是C:
概念相同,但功能名称不同.
If you know that you will be taking the square root of the result of the factorial function, just implement a function that directly computes the square root of factorial:

since factorial(n) is the product of the integers from 2 to n
square root of factorial(n) is the product of the square root of each of those integers from 2 to n

or, more efficient:

return Math.Pow(factorial(n), 0.5) (assuming factorial(n) is type double)

if your factorial(n) is returning BigInteger, then use Math.Exp(Math.BigInteger(factorial(n))/2.0)

I forgot that you indicated that the language you''re using is C:
The concepts are the same but the function names are different.


#include <stdio.h>
#include <math.h>

int main()
{
  long double c, n, fact = 1;
  printf("Enter a number to calculate it's factorial\n");
  scanf("%d", &n);
  for (c = 1; c <= n; c++)
  fact = fact * c;
  long double result=csqrtl(fact);
  printf("Squareroot of %d = %d\n", n, result);

  return 0;
}



-------------------------------------------------- --------------------------------------------------

有关平方根的更多详细信息,请参见.
http://www.codecogs.com/reference/computing/c/math.h/sqrt.php [ ^ ]

我认为这可以解决您的问题.


有关数据类型,请参见下面的我的解决方案



----------------------------------------------------------------------------------------------------

for more details on square root refer to..
http://www.codecogs.com/reference/computing/c/math.h/sqrt.php[^]

I think this solves your problem.


for data type see my solution below


这篇关于寻找阶乘的平方根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆