这里的问题
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