【HDU 2010】水仙花数

http://acm.hdu.edu.cn/showproblem.php?pid=2010

春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的:“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=1^3+5^3+3^3。现在要求输出所有在m和n范围内的水仙花数。

Solution:水仙花数又称阿姆斯特朗数,没有直接规律,只能暴力求解.

有限数列,打表算了(懒写暴力)

使用在线算法打大表:

1:  1, 2, 3, 4, 5, 6, 7, 8, 9
3: 153, 370, 371, 407
4: 1634, 8208, 9474
5: 54748, 92727, 93084
6: 548834
7: 1741725, 4210818, 9800817, 9926315
8: 24678050, 24678051, 88593477
9: 146511208, 472335975,534494836, 912985153
10: 4679307774, 32164049650
11:40028394225
11: 42678290603
11: 49388550606
11: 32164049651
11: 94204591914
11: 44708635679
11: 82693916578
14: 28116440335967
16: 4338281769391370
16: 4338281769391371
17: 21897142587612075
17: 35641594208964132
17: 35875699062250035
19: 1517841543307505039
19: 3289582984443187032
19: 4929273885928088826
19: 4498128791164624869
20: 63105425988599693916
21: 449177399146038697307
21: 128468643043731391252
23: 27907865009977052567814
23: 35452590104031691935943
23: 27879694893054074471405
23: 21887696841122916288858
24: 174088005938065293023722
24: 188451485447897896036875
..
有限序列,总共88最后一个115132219018763992565095597973971522401
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is.

#include <iostream>
#include <cstdio>
using namespace std;
int a[10]={153,370,371,407},b[10];
int main()
{
    freopen("2010.in","r",stdin);
    freopen("2010.out","w",stdout);
    int l,r,flag;
    while(~scanf("%d %d",&l,&r)){
        flag=0;
        for(int i=0;i<4;i++)
            if(a[i]>=l&&a[i]<=r)b[++flag]=a[i];
        if(flag){for(int i=1;i<flag;i++)printf("%d ",b[i]);printf("%d",b[flag]);}
        else printf("no");printf("
");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/YJinpeng/p/5987015.html