求满足下述两个条件的最小自然数n

求满足下述两个条件的最小自然数n:
(1) n的个位数字为8;
(2) 将n的个位数字8移到其它各位数字之前(如205128移过后为820512),所得的新数恰为n的4倍。

#include
using namespace std;
int maxa(void);
int main()
{
int n=8;
for(n=8;n {
int k=1;//记录n的位数
int x=n;
while(x/10!=0){
x=x/10;
k++;
}
x=(n>10)?(n/10):n;//去掉n的个位8
int firstnum=8;
for(int i=1;i firstnum=firstnum*10;
x+=firstnum;
if(x==n*4)//判断x是否是原来n值的4倍
break;
}
cout cin>>n;
return 0;
}

     // 写了一个C#版的,反正差不多
    static void Main(string[] args)
    {
        int oldNum = 8;
        int newNum = 0;
        int tempNum = 32;

        while (4 * oldNum != newNum)
        {
            int oldNumLenth = GetLength(oldNum);

            int carry = tempNum / 10;
            int unit = tempNum % 10;
            if (unit == 0)
            {
                oldNum += tempNum * (int)Math.Pow(10, oldNumLenth);
                tempNum = 4 * carry;
                oldNumLenth = GetLength(oldNum);
            }
            else
            {
                oldNum += unit * (int)Math.Pow(10, oldNumLenth);
                tempNum = 4 * unit + carry;
            }

            newNum = (oldNum - 8) / 10 + 8 * (int)Math.Pow(10, oldNumLenth - 1);
            Console.WriteLine(newNum + "      " + oldNum);
        }
    }

上面只需要把(int)Math.Pow(10, oldNumLenth)替换成(int)pow((double)10, oldNumLenth)这种类型就都一样了。GetLength(oldNum)是获取oldNum的位数。
很简单的啦。。。

图片说明