ITKeyword,专注技术干货聚合推荐

注册 | 登录

51NOD 1016 水仙花数 V2(打表)

qingshui23 分享于 2016-08-04

推荐:n位水仙花数

水仙花数指的是一个 n 位数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身。(例如:1^3 + 5^3 + 3^3 = 153) 下面代码,求19位,在E7200 2.53G的win xp 32

2019阿里云全部产品优惠券(新购或升级都可以使用,强烈推荐)
领取地址https://promotion.aliyun.com/ntms/yunparter/invite.html

传送门
水仙花数是指一个 n 位数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身。(例如:1^3 + 5^3 + 3^3 = 153,1634 = 1^4 + 6^4 + 3^4 + 4^4)。
给出一个整数M,求 >= M的最小的水仙花数。
Input
一个整数M(10 <= M <= 10^60)
Output
输出>= M的最小的水仙花数,如果没有符合条件的水仙花数,则输出:No Solution
Input示例
300
Output示例
370

推荐:循环-11. 水仙花数(20)

水仙花数是指一个N位正整数(N>=3),它的每个位上的数字的N次幂之和等于它本身。例 如:153 = 13 + 53+ 33。 本题要求编写程序,计算所有N位水仙花数。 输入格式

解题思路:
把 1060 以内的数都打表打出,然后判断就行了。

/** 2016 - 08 - 04 晚上 Author: ITAK Motto: 今日的我要超越昨日的我,明日的我要胜过今日的我, 以创作出更好的代码为目标,不断地超越自己。 **/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9+5;
const int MAXN = 1e6+5;
const int MOD = 1e9+7;
const double eps = 1e-7;
const double PI = acos(-1);
using namespace std;
string Narcissus[90] = {"0","1","2","3","4","5","6","7","8","9","153","370","371","407","1634",
"8208","9474","54748","92727","93084","548834","1741725","4210818","9800817","9926315",
"24678050","24678051","88593477","146511208","472335975","534494836","912985153",
"4679307774","32164049650","32164049651","40028394225","42678290603","44708635679",
"49388550606","82693916578","94204591914","28116440335967","4338281769391370",
"4338281769391371","21897142587612075","35641594208964132","35875699062250035",
"1517841543307505039","3289582984443187032","4498128791164624869","4929273885928088826",
"63105425988599693916","128468643043731391252","449177399146038697307",
"21887696841122916288858","27879694893054074471405","27907865009977052567814",
"28361281321319229463398","35452590104031691935943","174088005938065293023722",
"188451485447897896036875","239313664430041569350093","1550475334214501539088894",
"1553242162893771850669378","3706907995955475988644380","3706907995955475988644381",
"4422095118095899619457938","121204998563613372405438066","121270696006801314328439376",
"128851796696487777842012787","174650464499531377631639254","177265453171792792366489765",
"14607640612971980372614873089","19008174136254279995012734740",
"19008174136254279995012734741","23866716435523975980390369295",
"1145037275765491025924292050346","1927890457142960697580636236639",
"2309092682616190307509695338915","17333509997782249308725103962772",
"186709961001538790100634132976990","186709961001538790100634132976991",
"1122763285329372541592822900204593","12639369517103790328947807201478392",
"12679937780272278566303885594196922","1219167219625434121569735803609966019",
"12815792078366059955099770545296129367","115132219018763992565095597973971522400",
"115132219018763992565095597973971522401"};
int main()
{
    string s;
    while(cin>>s)
    {
        int len = s.size();
        for(int i=0; i<89; i++)
        {
            int tmp = Narcissus[i].size();
            if(tmp == len)
            {
                if(Narcissus[i] >= s)
                {
                    cout<<Narcissus[i]<<endl;
                    goto endW;
                }
            }
            if(tmp > len)
            {
                cout<<Narcissus[i]<<endl;
                goto endW;
            }
        }
        puts("No Solution");
        endW:;
    }
    return 0;
}

推荐:Java实现水仙花数

1、问题描述       打印出所有的 "水仙花数 ",所谓 "水仙花数 "是指一个三位数,其各位数字立方和等于该数本身。       如153是一个水仙花数,153=1的三次方+5

传送门 水仙花数是指一个 n 位数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身。(例如:1^3 + 5^3 + 3^3 = 153,1634 = 1^4 + 6^4 + 3^4 + 4^4)。 给出一个整数M,求 >= M的最小的水

相关阅读排行


用户评论

游客

相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。