l*********y 发帖数: 142 | 1 最后提交的时候发现结果溢出了,请问大家是怎么处理的?
我的最后的分子和分母都溢出。难道都要写好大数乘法做subroutine?
自己没有写过很多程序,请指教. 多谢了。 | l***i 发帖数: 1309 | 2 There are two ways, easy and hard.
The easy way would be using python or java BigInteger
The hard way is to write your own bigint or use GNU GMP.
Actually facebook is evil, in the testcases they just enumerate all primes
less than 500... | h**6 发帖数: 4160 | 3 提前写了大数类,往上一粘就可以了。
另外跟素不素数没有什么关系,如果分子分母不约分,最后乘积就会很大。我自己测试
程序的时候用的是
50 50 500 500 500 500 ... 500
得到结果 (499/500)^50
500^50 大约是10^135,为简化实现,可以用固定长度数组实现大数类。 |
|