标签:
Specialized Four-Digit Numbers
专业的4位数(扩展水仙花数)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4906 Accepted Submission(s): 3545
Problem Description
Find and list all four-digit numbers in decimal notation that have the property that the sum of its four digits equals the sum of its digits
找出且列出所有的 四位的十进制数,
when represented in hexadecimal (base 16) notation and also equals the sum of its digits when represented in duodecimal (base 12) notation.
满足: 用十进制表示其数字的总和 等于 用十六进制表示其数字的总和 等于 十二进制表示其数字的总和 。
For example, the number 2991 has the sum of (decimal) digits 2+9+9+1 = 21. Since 2991 = 1*1728 + 8*144 + 9*12 + 3,
举一个例子:2991 = 2+9+9+1 = 21,,2991 = 1*1728 + 8*144 + 9*12 + 3(求12进制数);
its duodecimal representation is 1893(12), and these digits also sum up to 21.
其十二进制表示是1893(12),1893 (12) = 1+8+9+3 = 21;
But in hexadecimal 2991 is BAF16, and 11+10+15 = 36, so 2991 should be rejected by your program.
但是其十六进制表示是BAF(16),BAF (16) = 11+ 10 + 15 = 36,所以2991 不满足要求。
The next number (2992), however, has digits that sum to 22 in all three representations (including BB016), so 2992 should be on the listed output.
在举一个例子(2992):2992 = 2 + 9 + 9 +2 = 22;
1894 (12) = 1 + 8 + 9 +4 = 22;
BB0 (16) = 11 + 11 + 0 = 22。
(We don‘t want decimal numbers with fewer than four digits - excluding leading zeroes - so that 2992 is the first correct answer.)
我们不想十进制数字少于四位数-不含前导零,2992是第一个正确答案。
Input
There is no input for this problem.
求四位数满足条件的,所以没有必要输入。
Output
Your output is to be 2992 and all larger four-digit numbers that satisfy the requirements (in strictly increasing order),
你的输出应该从 2992 开始 到 满足需求最大的四位数字 结束(数列单调递增),
each on a separate line with no leading or trailing blanks, ending with a new-line character.
每行输出没有多余的空格,且只输出一个数据。
There are to be no blank lines in the output.
没有空格行输出。
The first few lines of the output are shown below.
输出的前几行如下所示。
Sample Input
There is no input for this problem.
Sample Output
2992
2993
2994
2995
2996
2997
2998
2999
Source
public class Main {
public static void main(String[] args) {
for (int i = 2992; i < 10000; i++) {
if (calculateByteSum(i, 10) == calculateByteSum(i, 16)
&& calculateByteSum(i, 16) == calculateByteSum(i, 12)) {
System.out.println(i);
}
}
}
public static int calculateByteSum(int number, int type) {
int sum = 9;
while (number > 0) {
sum += number % type;
number /= type;
}
return sum;
}
}
Specialized Four-Digit Numbers
标签:
原文地址:http://blog.csdn.net/hncu1306602liuqiang/article/details/46343655