Problem 34—Digit factorials
来源:互联网 发布:淘宝的全球购是真的吗 编辑:程序博客网 时间:2024/06/05 23:57
题目描述如下:
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
Find the sum of all numbers which are equal to the sum of the factorial of their digits.
Note: as 1! = 1 and 2! = 2 are not sums they are not included.
public class Problem34{ public static void main(String[] args) { int sum = 0; for (int i = 3; i < 1000000; i++) { if (isCurious(i)) { System.out.println(i); sum += i; } } System.err.println("sum = " + sum); } public static boolean isCurious(int num) { int temp = num; int sum = 0; while (temp > 0) { sum += MathUtils.getFactorial(temp % 10); temp = temp / 10; } if (sum == num) { return true; } return false; }}
运行结果:
145
40585
sum = 40730
0 0
- Problem 34—Digit factorials
- [Euler]Problem 34 - Digit factorials
- (Problem 34)Digit factorials
- projecteuler---->problem=34----Digit factorials
- Project Euler:Problem 34 Digit factorials
- Problem 34 Digit factorials (暴力)
- No_33:Digit factorials
- 欧拉工程第34题:Digit factorials
- Digit Problem
- Problem 1106 Sum of Factorials
- Problem 1106 Sum of Factorials
- Problem 30—Digit fifth powers
- factorials
- Factorials
- Factorials
- Digit Problem
- Problem D: Digit Rightmost
- Problem 005——UVa 1583 - Digit Generator
- android-ndk-r10d r13b下载地址
- Map/Reduce API 样例一
- SSH登录日志分析脚本(Python)
- linux 命令系列之网络命令(12)
- eclipse常用插件的安装使用
- Problem 34—Digit factorials
- C#数组相乘
- Navicat Lite for MySQL说明及Mysql基础知识
- 改造AnimationUtils,改为RotateAnimation
- linux 命令系列之关机命令(13)
- Java实现发送邮件功能
- 从Windows到Ubuntu迁徙计划
- 4.22模拟总结
- C#值类型与引用类型,装箱与拆箱操作