水仙花数 (sdut oj)
来源:互联网 发布:你瞒我瞒网络链接 编辑:程序博客网 时间:2024/06/16 00:58
水仙花数
Time Limit: 1000MS Memory Limit: 65536KB
Problem Description
春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,是这样定义的:
“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=13+53+33。
现在要求输出所有在m和n范围内的水仙花数。
“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=13+53+33。
现在要求输出所有在m和n范围内的水仙花数。
Input
输入数据有多组,每组占一行,包括两个整数m和n(100<=m<=n<=999)。
Output
对于每个测试实例,要求输出所有在给定范围内的水仙花数,就是说,输出的水仙花数必须大于等于m,并且小于等于n,如果有多个,则要求从小到大排列在一行内输出,之间用一个空格隔开;
如果给定的范围内不存在水仙花数,则输出no;
每个测试实例的输出占一行。
如果给定的范围内不存在水仙花数,则输出no;
每个测试实例的输出占一行。
Example Input
100 120300 380
Example Output
no370 371
Hint
Author
HDOJ
参考代码
#include<stdio.h>int main(){ int m,n; int i; int sum; int a1,a2,a3; int flag; int temp; while(~scanf("%d%d",&m,&n)) { flag = 0; temp = 0; for(i = m; i <= n; i++) { a1 = i % 10; a2 = i / 10 % 10; a3 = i / 100; sum= a1 * a1 * a1 + a2 * a2 * a2 + a3 * a3 * a3; if(sum == i) { temp++; if(temp == 1) printf("%d",i); else printf(" %d",i); } else flag++; } if(flag == (n - m) + 1) printf("no"); printf("\n"); } return 0;}
0 0
- 水仙花数 (sdut oj)
- sdut oj1239 水仙花数
- SDUT-1239 水仙花数
- SDUT 1239 水仙花数
- 南阳OJ~~水仙花数
- 优越数 (sdut oj)
- 平方数 (sdut oj)
- OJ 30之水仙花数
- 求实数绝对值 (sdut oj)
- 计算组合数 (sdut oj)
- 计算组合数 (sdut oj)
- 删数问题 (sdut oj)
- 南阳oj 题目39 水仙花数
- zzuli OJ 1027: 判断水仙花数
- 杭电oj 2010 水仙花数
- 【杭电-oj】-2010-水仙花数
- 杭电OJ 2010.水仙花数
- 杭电oj---2010 水仙花数
- ffmpeg 将图片合成视频以及将内存数据合成视频
- (4)MyEclipse10安装aptana插件
- hover中的小坑
- 阿里巴巴技术笔试心得《技术之瞳》例题错误答案汇总(持续更新)
- 不用加减乘除做加法
- 水仙花数 (sdut oj)
- Cocoa 禁止APP多重启动
- FJOI2017 滚蛋记
- Android中的Service与进程间通信(IPC)详解
- python3 文档测试
- PHP的一些天坑
- addShutdownHook
- ThreadPoolExecutor机制(一)--基本介绍
- C语言贪吃蛇。