博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
D - Specialized Four-Digit Numbers
阅读量:6079 次
发布时间:2019-06-20

本文共 1987 字,大约阅读时间需要 6 分钟。

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 1893
12, and these digits also sum up to 21. But in hexadecimal 2991 is BAF
16, 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 BB0
16), 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

29922993299429952996299729982999... 依旧是submit failed,以下为我写的代码
#include 
using namespace std;int f(int n,int x){ int i=0,j,a[10],m=0; while(n!=0) { a[i++]=n%x; n=n/x; } for(j=0;j

以下是提交成功AC的代码

#include 
using namespace std;int f(int n,int x){ int a,m=0; while(n!=0) { a=n%x; n=n/x; m+=a; } return m;}int main(){ int n,i; for(i=2992;i<10000;i++){ n=i/1000+i/100%10+i/10%10+i%10; if(f(i,16)==n&&f(i,12)==n)cout<
<

发现我写的代码似乎太啰嗦了!!!麻烦!!许多东西完全可以省略!!!!

 

转载于:https://www.cnblogs.com/farewell-farewell/p/5171029.html

你可能感兴趣的文章
H5端调起百度地图、腾讯地图app
查看>>
yum安装软件报错Segmentation fault处理
查看>>
程序员45个好习惯
查看>>
关于保留页面状态的一些总结
查看>>
3 ways of including JavaScript in HTML
查看>>
js的Prototype属性 解释及常用方法
查看>>
EntityFramework 启用迁移 Enable-Migrations 报异常 "No context type was found in the assembly"
查看>>
SCC模板
查看>>
专题二经典问题解析_13
查看>>
和小猪一起搞微信公众号开发—创建自定义菜单
查看>>
C# 检测网络链接
查看>>
WPF 让Enter键按下时默认为某按钮(Button)事件
查看>>
Nginx下配置codeigniter框架
查看>>
git学习笔记(1)
查看>>
面试题3
查看>>
lucene全文检索技术
查看>>
java某课程安排
查看>>
Algs4-2.2.16自然的归并排序
查看>>
链表的基本操作(Basic Operations on a Linked List)
查看>>
Codeforces Round #195 (Div. 2) 解题报告
查看>>