所以问题是试图输入100000号,但是我得到了, 输出= 0 而且我也不能全部粘贴100000号。在cmd
import java.util.Scanner;
class practise{
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
long num = 1, numb = 1;
long arr[] = new long[100000];
for(int i = 0; i < 100000 ; i++){
arr[i] = scan.nextInt();
}
for(int j = 0 ; j < 10000 ; j++){
if(arr[j] == 0){
num = num * numb;
numb++ ;
}
}
System.out.println(num);
}
}
答案 0 :(得分:0)
如果N个数字== 0,您应该得到N!结果。这甚至可能溢出很长时间(64位)。顺便祝您调试愉快。似乎不需要数组,不是吗?
N!是结果,因此计算因子2,并且至少应该有N / 2个偶数因子(实际上,因子8会给出3个因子2),对于N> = 128(甚至〜100),乘积为0。 / p>
Scanner scan = new Scanner(System.in);
long result = 1L;
int num = 1;
for (int i = 0; i < 100_000 ; i++){
int numb = scan.nextInt();
if (numb == 0) {
result *= num;
++num;
if (result == 0L) {
System.out.println("Stopping at i = " + i + ", num = " + num);
break; // result would stay 0.
}
}
}
System.out.println(result);
一个人可以使用BigInteger,但我认为该任务旨在将...溢出为0。 也许发现您不需要读取所有数字,也无需将它们存储在数组中。