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, its duodecimal representation is 189312, and these digits also sum up to 21. But in hexadecimal 2991 is BAF16, and 11+10+15
= 36, so 2991 should be rejected by your program. 

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. (We don't want decimal numbers with fewer than four digits -- excluding leading zeroes -- so that 2992
is the first correct answer.) 

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), 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
...
#include <iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int x,y;
int sa(int i)
{
y=0;
while(i!=0)
{ y+=i%10;
i=i/10;
}
return y;
}
int sb(int i)
{
y=0;
while(i!=0)
{ y+=i%12;
i=i/12;
}
return y;
}
int sc(int i)
{
y=0;
while(i!=0)
{ y+=i%16;
i=i/16;
}
return y;
}
int main()
{
int a,b,c,n,i,d; for(i=2992;i<10000;i++)
{
a=sa(i);
b=sb(i);
c=sc(i);
if(a==b&&b==c)
printf("%d\n",i);
} return 0;
}

G - Specialized Four-Digit Numbers(1.5.2)的更多相关文章

  1. [Swift]LeetCode902. 最大为 N 的数字组合 | Numbers At Most N Given Digit Set

    We have a sorted set of digits D, a non-empty subset of {'1','2','3','4','5','6','7','8','9'}.  (Not ...

  2. 902. Numbers At Most N Given Digit Set

    We have a sorted set of digits D, a non-empty subset of {'1','2','3','4','5','6','7','8','9'}.  (Not ...

  3. LeetCode902. Numbers At Most N Given Digit Set

    题目: We have a sorted set of digits D, a non-empty subset of {'1','2','3','4','5','6','7','8','9'}.  ...

  4. [LeetCode] 902. Numbers At Most N Given Digit Set 最大为 N 的数字组合

    We have a sorted set of digits D, a non-empty subset of {'1','2','3','4','5','6','7','8','9'}.  (Not ...

  5. 【Kickstart】2017 Round (Practice ~ G)

    Practice Round Problem A Country Leader (4pt/7pt) Problem B Vote (5pt/8pt) Problem C Sherlock and Pa ...

  6. PAT/进制转换习题集

    B1022. D进制的A+B (20) Description: 输入两个非负10进制整数A和B(<=230-1),输出A+B的D (1 < D <= 10)进制数. Input: ...

  7. js判断小数点几位

    js如何判断小数点后有几位 <script> var n=3.143423423;alert(n.toString().split(".")[1].length); & ...

  8. 数据结构——POJ 1686 Lazy Math Instructor 栈的应用

    Description A math instructor is too lazy to grade a question in the exam papers in which students a ...

  9. Inside a low budget consumer hardware espionage implant

    The following analysis was performed on a S8 data line locator which replied to the hidden SMS comma ...

随机推荐

  1. 图解spring事务管理的实现

  2. Spring Cloud(2.0)能力大致列表

    微服务九大特性 出自Martin Fowler的<Microservices> 服务组件化 按业务组织团队 做"产品"的态度 智能端点与哑管道 去中心化治理 去中心化管 ...

  3. Install Oracle 11G Release 2 (11.2) on Centos Linux 7

    Install Oracle 11G Release 2 (11.2) on Centos Linux 7 This article presents how to install Oracle 11 ...

  4. 九度oj 题目1083:特殊乘法 清华大学2010年机试题目

    题目描述: 写个算法,对2个小于1000000000的输入,求结果. 特殊乘法举例:123 * 45 = 1*4 +1*5 +2*4 +2*5 +3*4+3*5 输入: 两个小于1000000000的 ...

  5. Python Excel导入数据库

    import xlrd import MySQLdb def inMySQL(file_name): wb = xlrd.open_workbook(file_name) sh = wb.sheet_ ...

  6. ACM程序设计选修课——1065: Operations on Grids(暴力字符串)

    1065: Operations on Grids Time Limit: 3 Sec  Memory Limit: 128 MB Submit: 17  Solved: 4 [Submit][Sta ...

  7. [解决方案][错误代码:0x80070002]IIS7及以上伪静态报错404

    故障现象:DTCMS开启伪静态功能,VS2010预览正常,发布到IIS后报错404.0错误 (WIN7,WIN8,SERVER2008).模块IISWebCore通知MapRequestHandler ...

  8. struts2是什么

    Struts2是什么: Struts2是整合了struts1和webwork的技术优点的使用广泛的MVC框架: Struts2的特点: 1.基于MVC框架,结构清晰,便于开发人员掌控开发流程: 2.使 ...

  9. [转] Makefile 基础 (2) —— Makefile 总述

    该篇文章为转载,是对原作者系列文章的总汇加上标注. 支持原创,请移步陈浩大神博客:(最原始版本) http://blog.csdn.net/haoel/article/details/2886 我转自 ...

  10. javaweb学习总结(十六)——JSP指令(转)

    一.JSP指令简介 JSP指令(directive)是为JSP引擎而设计的,它们并不直接产生任何可见输出,而只是告诉引擎如何处理JSP页面中的其余部分. 在JSP 2.0规范中共定义了三个指令: pa ...