首页
社区
课程
招聘
[求助]一个计算求值(已解决)
2006-8-25 09:28 5078

[求助]一个计算求值(已解决)

2006-8-25 09:28
5078
编程实现:求所有的7位数.它的十六进制值等于每位数字7次方的和.
Hex(abcdefg)=a7+ b7+ c7+ d7+ e7+ f7+ g7
有什么最快的方法

下面的方法需要三、四分钟,而且不知道答案是否正确:
function cacl(a: integer): integer;  //求六次方的函数
  var
    b:integer;
  begin
      b:=0;
      asm
      xor eax,eax
      xor esi,esi
      mov eax,a
      mov ecx,eax
      mov esi,$6
    @:
      imul eax,ecx
      dec esi
      jne @
      mov b,eax
      end;
      Result := b;
  end;

procedure TForm1.Button1Click(Sender: TObject);
var
   s,i:integer;
   c:string;
   d:string;
begin
    repeat
    i := 1000000 + Random(9999999);
    d:=inttostr(i);
    s:=cacl(strtoint(midstr(d,1,1)))+
       cacl(strtoint(midstr(d,2,1)))+
       cacl(strtoint(midstr(d,3,1)))+
       cacl(strtoint(midstr(d,4,1)))+
       cacl(strtoint(midstr(d,5,1)))+
       cacl(strtoint(midstr(d,6,1)))+
       cacl(strtoint(midstr(d,7,1)));

     until
      s=i;

      edit1.Text:=inttostr(i);
end;

end.

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
点赞7
打赏
分享
最新回复 (9)
雪    币: 333
活跃值: (11)
能力值: ( LV12,RANK:770 )
在线值:
发帖
回帖
粉丝
jdxyw 19 2006-8-26 19:59
2
0
雪    币: 560
活跃值: (309)
能力值: ( LV13,RANK:1370 )
在线值:
发帖
回帖
粉丝
laomms 34 2006-8-29 07:55
3
0
随机法不行,用了穷举法,C1.7,奇慢无比,N久算不出注册码,不知还有没有其它方法:

begin
    for i := 1000000 to 9999999   do
    begin
    d:=inttostr(i);
    s1:=cacl(strtoint(midstr(d,1,1)));
    s2:=cacl(strtoint(midstr(d,2,1)));
    s3:=cacl(strtoint(midstr(d,3,1)));
    s4:=cacl(strtoint(midstr(d,4,1)));
    s5:=cacl(strtoint(midstr(d,5,1)));
    s6:=cacl(strtoint(midstr(d,6,1)));
    s7:=cacl(strtoint(midstr(d,7,1)));
    s:=s1+s2+s3+s4+s5+s6+s7;
    if inttostr(s)=d   then
       ListBox1.Items.Add(inttostr(s));
    end;
end;
雪    币: 207
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
w三二dasm 2006-8-29 10:08
4
0
最初由 laomms 发布
随机法不行,用了穷举法,C1.7,奇慢无比,N久算不出注册码,不知还有没有其它方法:

begin
for i := 1000000 to 9999999 do
begin
........

让你的下一代继续算
雪    币: 560
活跃值: (309)
能力值: ( LV13,RANK:1370 )
在线值:
发帖
回帖
粉丝
laomms 34 2006-8-29 11:13
5
0
搞定:
#include<stdio.h>
#define power(t) t*t*t*t*t*t*t
const int M=1000000;
const int N=9999999;
int vaild(int m)
{
    int r,t=m,sum=0;
    while(m)
    {
        r=m%10;
        m/=10;
        sum+=power(r);
    }
    return sum==t?1:0;
}

int main()
{
    int i;
    char ch;
    for(i=M;i<N;i++)
    {
        if(vaild(i))printf("%d\n",i);
    }
    ch=getchar();
    return 0;
}

雪    币: 560
活跃值: (309)
能力值: ( LV13,RANK:1370 )
在线值:
发帖
回帖
粉丝
laomms 34 2006-8-29 12:20
6
0
终于搞定,速度还可以.
雪    币: 179
活跃值: (131)
能力值: ( LV12,RANK:290 )
在线值:
发帖
回帖
粉丝
WAKU 7 2006-8-29 21:40
7
0
不好意思,我好像没看明白你的题意,但是从你上面的图中第一个数:
hex(1741725) = 1A939D
1^7+7^7+4^7+1^7+2^7+5^7 = 918182
也不等啊
雪    币: 560
活跃值: (309)
能力值: ( LV13,RANK:1370 )
在线值:
发帖
回帖
粉丝
laomms 34 2006-8-30 07:24
8
0
最初由 WAKU 发布
1^7+7^7+4^7+1^7+2^7+5^7 = 918182
也不等啊


好象少了一项吧,计算式中只有6项.

1^7+7^7+4^7+1^7+2^7+5^7 =1+823543+16384+1+823543+128+78125=1741725

还要转16进制,因为10进制不可能跟16进制比较.或者直接用10进制比较.
雪    币: 179
活跃值: (131)
能力值: ( LV12,RANK:290 )
在线值:
发帖
回帖
粉丝
WAKU 7 2006-8-30 12:25
9
0
晕...你这不是类似水仙花数求值么
那和16进制也没关系啊

我以为是这样的:
比如16进制数555555,换成10进制是5592405
那么5^7+5^7+9^7...+5^7应该等于555555(当然这个不等于)
有道理没?
雪    币: 560
活跃值: (309)
能力值: ( LV13,RANK:1370 )
在线值:
发帖
回帖
粉丝
laomms 34 2006-8-30 15:43
10
0
有道理,可能我没有表达清楚,呵呵!
游客
登录 | 注册 方可回帖
返回