无心人 发表于 2011-9-12 19:41:50

立方数数字和问题

沿袭平方数数字和问题的描述
http://bbs.emath.ac.cn/thread-642-1-1.html

考虑平方数
先给出递归公式
T(0) = 0
N(0) = 0
F(0) = 1
T(i+1)=T(i)+F(i)
N(i+1)=N(i)+6
F(i+1)=F(i)+N(i)

则,T(0)...T(i)形成一系列的平方数

无心人 发表于 2011-9-12 20:58:05

代码
#include <stdio.h>
#include <stdlib.h>

#define M 6
#define D6 1000000

int D;
int T;
int N;
int F;
int dT, dN, dF;
int mask;

void init(void)
{
int i, j, k, l, m, n;
for (i = 0; i <= 9; i ++)
    for (j = 0; j <= 9; j ++)
      for (k = 0; k <= 9; k ++)
      for (l = 0; l <= 9; l ++)
          for (m = 0; m <= 9; m ++)
            for (n = 0; n <= 9; n ++)
            D = i + j + k + l + m + n;

for (i = 0; i < M; i ++)
    T = N = F = 0;
F = 1;   
dT = dN = dF = 1;
for (i = 0; i < 480; i ++)
    mask = 0;
}

void newT( void )
{
int i, t = 0;
for (i = 0; i < dF; i ++)
{
    t += T + F;
    t >= D6 ? (T = t - D6, t = 1) : (T = t, t = 0);
}
i = dF;
while ((t > 0)&& (i < dT))
{
    t += T;
    t >= D6 ? (T = t - D6, t = 1) : (T = t, t = 0);
    i ++;
}
if (t > 0)
    T = 1;
}


void newN( void )
{
int i = 0, t = 6;
while ((t > 0) && (i < dN))
{
    t += N;
    t >= D6 ? (N = t - D6, t = 1) : (N = t, t = 0);
    i ++;
}
if (t > 0)
    N = 1;
}

void newF( void )
{
int i, t = 0;
for (i = 0; i < dN; i ++)
{
    t += F + N;
    t >= D6 ? (F = t - D6, t = 1) : (F = t, t = 0);
}
i = dN;
while ((t > 0)&& (i < dF))
{
    t += F;
    t >= D6 ? (F = t - D6, t = 1) : (F = t, t = 0);
    i ++;
}
if (t > 0)
    F = 1;
}

void checkT( void )
{
int i, t = 0;
for (i = 0; i < dT; i ++)
    t += D];
if (mask == 0)
{
    printf("Find %d: ", t);
    i = dT - 1;
    printf("%d", T);
    while (i >= 0)
      printf("%06d", T);
    printf("\n");
    mask = 1;
}
}

void checkVar( int * v, int len)
{
if (len <= 0)
    return ;
printf("%d", v[-- len]);
while ( len > 0)
    printf("%06d", v[-- len]);
printf("\n");
}

int main( void )
{
long long i = 0;
init( );
while ( i <= 100000000 )
{
    //printf("%d: %d %d %d T, N, F====\n", i, dT, dN, dF);
    //checkVar(T, dT);
    //checkVar(N, dN);
    //checkVar(F, dF);
    newT( );
    newN( );
    newF( );
    checkT( );
    i ++;
}
}

无心人 发表于 2011-9-12 20:59:13

10^24内结果
Find 1: 1
Find 8: 8
Find 9: 27
Find 10: 64
Find 18: 729
Find 19: 2197
Find 17: 2744
Find 28: 6859
Find 26: 17576
Find 27: 19683
Find 35: 148877
Find 36: 287496
Find 37: 438976
Find 44: 778688
Find 45: 2299968
Find 46: 3869893
Find 53: 43986977
Find 54: 75686967
Find 55: 174676879
Find 62: 596947688
Find 63: 796597983
Find 64: 1693669888
Find 73: 7598896696
Find 71: 9649992689
Find 72: 56888939736
Find 80: 78898389569
Find 81: 197747699976
Find 82: 677298787768
Find 89: 1778597976896
Find 98: 1999899757799
Find 90: 4329949978899
Find 91: 6999657683689
Find 100: 27969886988875
Find 99: 68986579789197
Find 107: 254996898985997
Find 108: 299982589968888
Find 109: 994878767299789
Find 116: 2679768989786699
Find 118: 9949889468976787
Find 117: 18696769447799997
Find 125: 39677989979796875
Find 126: 129937879999769499
Find 127: 188979889884278779
Find 135: 849894379779889989
Find 136: 968397868897889977
Find 134: 1737876998969969768
Find 144: 9688689596689799688
Find 143: 19786889787799686488
Find 145: 48879314999968898899
Find 154: 67988999959868987875
Find 153: 85897988298989489979
Find 152: 179999887787788988375
Find 162: 2979909779796589978989
Find 161: 4479959888985687898688
Find 163: 8783893698974994898999
Find 170: 67899899689199886577697
Find 171: 68885699985378975978999
Find 172: 84997849968878977898776
Find 179: 529967889999499896479969
Find 181: 688859969398989879749896

无心人 发表于 2011-9-12 21:59:59

四次方递归公式
Q(0)=0
F(0)=1
N(0)=14
M(0)=36
Q(i+1)=Q(i)+F(i)
F(i+1)=F(i)+N(i)
N(i+1)=N(i)+M(i)
M(i+1)=M(i)+24
Q(i)组成四次方序列

sprime 发表于 2012-2-10 13:52:18

多谢分享!
页: [1]
查看完整版本: 立方数数字和问题