欧拉项目 第20题 Factorial digit sum
2016-03-18 10:42
316 查看
n! means n × (n − 1) × ... × 3 × 2 × 1
For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
Find the sum of the digits in the number 100!
求100!个位数和。
For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
Find the sum of the digits in the number 100!
求100!个位数和。
public static void main(String[] args) { long start = System.currentTimeMillis(); BigInteger x = BigInteger.ONE; for(Integer i=2;i<100;i++) { x = x.multiply(BigInteger.valueOf(i)); // if(x.divideAndRemainder(new BigInteger("10"))[1].compareTo(new BigInteger("0")) == 0) { // x = x.divide(new BigInteger("10")); // } } Integer sum = 0; String sx = x.toString().replaceAll("0", ""); for(int i=0;i<sx.length();i++) { sum += Integer.parseInt(sx.substring(i, i + 1)); //<span style="font-family: monospace; font-size: 12.87px; white-space: pre-wrap;"> Character.getNumericValue(sx.charAt(i));</span> } System.out.println(sum); System.out.println(System.currentTimeMillis() - start); }
相关文章推荐
- iOS CocoaPods安装和使用图解
- arcGis基本知识
- CoreLocation框架地图定位(iOS9全适配)
- Java线程面试题
- 如何让NSURLConnection在子线程中运行
- 出差(二十三)
- 查看和修改MySQL数据库表存储引擎
- SqlServer---RowCount 和 @@RowCount的用法和区别
- 采购订单通过open interface导入
- eclipse插件地址
- 灵活的 switch
- 解决No Certificates are available
- SpringMVC和Struts2区别与比较总结
- git强行换分支 gitpull问题解决
- 【Solr】新建core后,启动服务访问web报错 HTTP Status 503
- 开发简单的Kafka应用
- hdu2011java
- 【Git】无法从远程分支pull
- 强大的nth-child(n)伪类选择器玩法 企
- UICollectionView 多选显示问题