51Nod 1016 水仙花数 V2
来源:互联网 发布:金城学院继续教育jaVa 编辑:程序博客网 时间:2024/06/05 23:54
水仙花数是指一个 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
讨论区里有个水仙花数的表!自己手算也懒得算了。。。偷个懒打个表吧。。。。。。
以下是水仙花数表
01234567891533703714071634820894745474892727930845488341741725421081898008179926315246780502467805188593477146511208472335975534494836912985153467930777432164049650321640496514002839422542678290603447086356794938855060682693916578942045919142811644033596743382817693913704338281769391371218971425876120753564159420896413235875699062250035151784154330750503932895829844431870324498128791164624869492927388592808882663105425988599693916128468643043731391252449177399146038697307218876968411229162888582787969489305407447140527907865009977052567814283612813213192294633983545259010403169193594317408800593806529302372218845148544789789603687523931366443004156935009315504753342145015390888941553242162893771850669378370690799595547598864438037069079959554759886443814422095118095899619457938121204998563613372405438066121270696006801314328439376128851796696487777842012787174650464499531377631639254177265453171792792366489765146076406129719803726148730891900817413625427999501273474019008174136254279995012734741238667164355239759803903692951145037275765491025924292050346192789045714296069758063623663923090926826161903075096953389151733350999778224930872510396277218670996100153879010063413297699018670996100153879010063413297699111227632853293725415928229002045931263936951710379032894780720147839212679937780272278566303885594196922121916721962543412156973580360996601912815792078366059955099770545296129367115132219018763992565095597973971522400115132219018763992565095597973971522401
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<cmath>#include<map>#include<queue>#include<algorithm>#define max(a,b) (a>b?a:b)#define swap(a,b) (a=a+b,b=a-b,a=a-b)using namespace std;typedef long long int LL;const int MAXL(50000);const int MAX(0x3f3f3f3f);string str[100]={"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 len=88;bool Compare(string first,string second){ int i=0; while(first[i]=='0') i++; first.erase(0,i); i=0; while(second[i]=='0') i++; second.erase(0,i); int len1=first.size(); int len2=second.size(); if(len1<len2) return false; else if(len1==len2 && first<second) return false; return true;}int main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //init(); string t; cin>>t; for(int i=0;i<=len;i++) { if(Compare(str[i],t)==true) { cout<<str[i]<<endl; return 0; } } cout<<"No Solution"<<endl;}
阅读全文
0 0
- 51Nod 1016 水仙花数 V2
- 51nod-1016-水仙花数 V2
- 51Nod 1016 水仙花数 V2
- 51Nod-1016-水仙花数 V2
- 51nod 1016 水仙花数 V2 打表
- 51NOD 1016 水仙花数 V2(打表)
- 1016 水仙花数 V2
- 1016 水仙花数 V2
- 51Nod 水仙花数
- 51Nod 1016 水仙花数 打表
- 51nod1016 水仙花数 V2
- 51NOD 1015 水仙花数
- 51nod 1015 水仙花数
- 51nod 1015 水仙花数
- 51nod-【1015 水仙花数】
- 51nod 1015 水仙花数
- 51Nod 1015 水仙花数
- 【51Nod】1015 水仙花数
- VMware下安装CentOs 7(上)
- ROS配置<一>:Ubuntu16.04下安装Kinetic
- HTML排版标签
- Java实现对cookie的增删改查
- Struts2-01
- 51Nod 1016 水仙花数 V2
- ONOS安装及编译步骤(附编译出现问题的几种解决方法)
- ARKit如何将太阳系装进iPhone
- 深入理解Android消息机制
- UIViewController 中常见时序记录(layoutSubViews 与 XXXXappear/disappear 相关)
- jquery操作样式
- bzoj2243 [SDOI2011]染色 树链剖分
- yii 基于php的Rbac权限控制
- thriftserver&beeline的使用