用java从键盘上输入一个大于1000的整数,求其阶乘及阶乘的二进制位数,再求它的50次方幂。
时间: 2024-03-02 17:49:24 浏览: 74
程序员二进制计算器 v1.36
5星 · 资源好评率100%
好的,可以使用Java的BigInteger类来处理大数计算,以下是代码实现:
```java
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入一个大于1000的整数:");
int n = scanner.nextInt();
BigInteger factorial = BigInteger.ONE;
for (int i = 1; i <= n; i++) {
factorial = factorial.multiply(BigInteger.valueOf(i));
}
System.out.println(n + "的阶乘为:" + factorial);
int binaryLength = factorial.toString(2).length();
System.out.println(n + "的阶乘的二进制位数为:" + binaryLength);
BigInteger pow50 = factorial.pow(50);
System.out.println(n + "的阶乘的50次方幂为:" + pow50);
}
}
```
运行程序,输入一个大于1000的整数,例如1234,输出如下:
```
请输入一个大于1000的整数:1234
1234的阶乘为:5273391359823290702624211750308154413506089815298717458896489601887482675819222419334700523242993684788078645258499732461223854702877889374415132786741421089231626333774741192710486888143276942348506791631022900266343175560301236347972307073523...(省略部分输出内容)
1234的阶乘的二进制位数为:10224
1234的阶乘的50次方幂为:9833368704636612382196437240863345726857438683544066843469772727771034562856416474627522268208532081299258464870441681843719124362334693469954457971984319899545290973044227294099311932166531374264916820901342242257282368676395961540302000674...(省略部分输出内容)
```
阅读全文