输出所有水仙花数

来源:互联网 发布:寻秦ol源码 编辑:程序博客网 时间:2024/03/29 19:02

Description

打印出所有"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该本身。例如:153是一个水仙花数,因为153=1^3+5^3+3^3。 Output:

153370371407

Input

Output

所有的水仙花数,从小的开始。每行一个

Sample Input

Sample Output

HINT


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
usingnamespace std;
intmain()
{
    intn,a,b,c;
    for(n=100;n<1000;n++)
    {
        a=n/100; //分别获取百位、十位、个位,进行检验
        b=n/10-a*10;
        c=n%10;
        if(n==a*a*a+b*b*b+c*c*c) cout<<n<<endl;
        elsecontinue;
    }
    return0;
}
/**************************************************************
    Problem: 1036
    User: 201358501133
    Language: C++
    Result: Accepted
    Time:0 ms
    Memory:1264 kb
****************************************************************/

0 0
原创粉丝点击