acm水仙花数c语言程序,【HDU 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, 94745: 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#include

using namespacestd;int a[10]={153,370,371,407},b[10];intmain()

{

freopen("2010.in","r",stdin);

freopen("2010.out","w",stdout);intl,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

}return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值