Specialized Four-digit Numbers
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 4603 Accepted Submission (s): 3344
Problem Descriptionfind and list all four-digit numbers in decimal notation that has the property, the sum of its fou R digits equals the sum of its digits when represented in hexadecimal (base) notation and also equals the sum of its di Gits when represented in Duodecimal (base) 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, its duodecimal representation is 1893 (a), and these digits also sum up to 21. Hexadecimal 2991 is BAF16, and 11+10+15 = $, so 2991 should was rejected by your program.
The next number (2992), however, have digits that sum to + all three representations (including BB016), so 2992 should Be on the listed output. (We don ' t want decimal numbers with fewer than four digits-excluding leading zeroes-so this 2992 is the first correct Answer.)
Inputthere is no input for this problem.
Outputyour output is to being 2992 and all larger four-digit numbers this satisfy the requirements (in strictly increasing or Der), each on a separate line with no leading or trailing blanks, ending with a new-line character. There is to is no blank lines in the output. The first few lines of the output is shown below.
Sample Input
There is no input for this problem.
Sample Output
29922993299429952996299729982999
Sourcepacific Northwest 2004
#include <iostream>using namespace std;int sum (int n,int b) {int s=0;while (n) {s+=n%b;n/=b;} return s;} int main () {int x;for (x=1000;x<10000;x++) {if ((sum (x,16) ==sum (x,12)) && (sum (x,12) ==sum (x,10)) cout< <x<<endl;} return 0;}
Hangzhou Electric HDU 1197 Specialized four-digit Numbers