有一八层灯塔,每层的灯数都是上一层的两倍,共有765盏灯,求最上层与最下层的灯数。
我用穷举,这个为什么有毛病#include<stdio.h>int main(){
int a,b,c,d,e,f,g,h;
for(a = 1;a <= 765;a++)
for(b = 1;b <= 765;b++)
for(c = 1;c <= 765;c++)
for(d = 1;d <= 765;d++)
for(f = 1;f <= 765;f++)
for(e = 1;e <= 765;e++)
for(g = 1;g <= 765;g++)
for(h = 1;h <= 765;h++)
if(b / a == 2 && c / b == 2 && d / c == 2 && e / d == 2 && f /e == 2 && g / f == 2 && h / g == 2)
{
printf("the first floor has %d\n",a);
printf("the eight floor has %d\n",h);
}
}