English 中文(简体)
Euler项目 29
原标题:Project Euler 29
  • 时间:2012-01-12 09:48:30
  •  标签:
  • c

这里的问题

2. 考虑^2 combination5和2 ≤b 5 的混合物:

2^2=4, 2^3=8, 2^4=16, 2^5=32
3^2=9, 3^3=27, 3^4=81, 3^5=243
4^2=16, 4^3=64, 4^4=256, 4^5=1024
5^2=25, 5^3=125, 5^4=625, 5^5=3125

如果它们按数字顺序排列,并删除任何重复之处,我们有以下15种不同术语的顺序:

4、8、9、16、25、27、32、64、81、125、243、256、625、1024、3125

^ 2 ≤ 100 和 2 ≤ b 100 sequence 100 sequenceb 生成的序列中有多少不同术语?

我的法典

int b[10000][300]={};
int a[10000][300]={};
int main(void)
{
    int i,j,k=0,z;
    int ticker=2;
    int carry=0,oi=0;
    int carry1=0,count=0;
    for(i=0;i<10000;i++)
    {
        a[i][0]=1;
    }

    for(k=0;k<100;k++)
    {
        for(i=0;i<100;i++)
        {
            for(j=0;j<300;j++)
            {   
                carry1=(ticker*a[k][j]+carry)/10;
                a[k][j]=(ticker*a[k][j]+carry)%10;
                carry=carry1;
            }
            for(z=0;z<300;z++)
            {
                b[oi][z]=a[k][z]; // Storing the number, everytime its multiplied
            }
            oi++;
            carry1=0;
            carry=0;
        }
        ticker++;
    }
    int l=0,flag=0,blue=0;
    for(z=0;z<9900;z++)
    {

        for(i=0;i<9900;i++)
        {
            for(j=0;j<205;j++)
            {
                if(b[z][j]!=b[i][j])
                {
                    blue++;
                    break;
                }
            }
        }
        if(blue==9899)
        {
            l++;
        }
        blue=0;
    }
    printf("
%d
",l-99);
    return(0);
}

And here s my explanation. Since C can t handle large numbers, I decided to store every number that you get by a^b in an array by devising an algorithm for multiplication. Ie i store the digits of that number in an array. I then check which of the numbers in the array are the same and eliminate them. It s simple. But somehow I m not getting the right answer which is 9183, and have looked at my code several times but can t find the glitch Help me out guys. Thanks

最佳回答

如果我正确理解你的代码,你将最后的24小时重新计算unique。 这意味着你根本不计算16 = 2^4 = 4^2 = 16^1。

如果你在不计算复制件的情况下算出复制件,那么你可以用“<条码>int来解决这个问题(不破坏问题)。

问题回答

I think that your problem is in the bounds of the loops. for example, you store the numbers after one iterate of multiplication, which mean (n^1). I suggest you to reduce variables. the code will than be more readable, and the potential of mistakes will go down.





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签