51nod-1016-水仙花数 V2

本文介绍了一种通过预计算表格来快速查找大于等于给定数值的最小水仙花数的方法。水仙花数是一种特殊的整数,其每位数字的n次幂之和等于该数本身。文章提供了一个具体的实现案例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目描述

水仙花数是指一个 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

题解

写完代码的我完全不想在写题解
那就两个字:打表:)

var i:longint;
    str:array[0..90] of string;
    s:string;
begin
  readln(s);
  for i:=1 to 10 do str[i]:=chr(ord(i)-49);
  str[11]:='153';
  str[12]:='370';
  str[13]:='371';
  str[14]:='407';
  str[15]:='1634';
  str[16]:='8208';
  str[17]:='9474';
  str[18]:='54748';
  str[19]:='92727';
  str[20]:='93084';
  str[21]:='548834';
  str[22]:='1741725';
  str[23]:='4210818';
  str[24]:='9800817';
  str[25]:='9926315';
  str[26]:='24678050';
  str[27]:='24678051';
  str[28]:='88593477';
  str[29]:='146511208';
  str[30]:='472335975';
  str[31]:='534494836';
  str[32]:='912985153';
  str[33]:='4679307774';
  str[34]:='32164049650';
  str[35]:='32164049651';
  str[36]:='40028394225';
  str[37]:='42678290603';
  str[38]:='44708635679';
  str[39]:='49388550606';
  str[40]:='82693916578';
  str[41]:='94204591914';
  str[42]:='28116440335967';
  str[43]:='4338281769391370';
  str[44]:='4338281769391371';
  str[45]:='21897142587612075';
  str[46]:='35641594208964132';
  str[47]:='35875699062250035';
  str[48]:='1517841543307505039';
  str[49]:='3289582984443187032';
  str[50]:='4498128791164624869';
  str[51]:='4929273885928088826';
  str[52]:='63105425988599693916';
  str[53]:='128468643043731391252';
  str[54]:='449177399146038697307';
  str[55]:='21887696841122916288858';
  str[56]:='27879694893054074471405';
  str[57]:='27907865009977052567814';
  str[58]:='28361281321319229463398';
  str[59]:='35452590104031691935943';
  str[60]:='174088005938065293023722';
  str[61]:='188451485447897896036875';
  str[62]:='239313664430041569350093';
  str[63]:='1550475334214501539088894';
  str[64]:='1553242162893771850669378';
  str[65]:='3706907995955475988644380';
  str[66]:='3706907995955475988644381';
  str[67]:='4422095118095899619457938';
  str[68]:='121204998563613372405438066';
  str[69]:='121270696006801314328439376';
  str[70]:='128851796696487777842012787';
  str[71]:='174650464499531377631639254';
  str[72]:='177265453171792792366489765';
  str[73]:='14607640612971980372614873089';
  str[74]:='19008174136254279995012734740';
  str[75]:='19008174136254279995012734741';
  str[76]:='23866716435523975980390369295';
  str[77]:='1145037275765491025924292050346';
  str[78]:='1927890457142960697580636236639';
  str[79]:='2309092682616190307509695338915';
  str[80]:='17333509997782249308725103962772';
  str[81]:='186709961001538790100634132976990';
  str[82]:='186709961001538790100634132976991';
  str[83]:='1122763285329372541592822900204593';
  str[84]:='12639369517103790328947807201478392';
  str[85]:='12679937780272278566303885594196922';
  str[86]:='1219167219625434121569735803609966019';
  str[87]:='12815792078366059955099770545296129367';
  str[88]:='115132219018763992565095597973971522400';
  str[89]:='115132219018763992565095597973971522401';
  for i:=1 to 89 do
    if (length(str[i])>length(s)) or (length(str[i])=length(s)) and (str[i]>s) then
    begin writeln(str[i]); halt end;
  if i=89 then writeln('No Solution');
end.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值