Basic ------ 12. Guess age

topic:

N. Wiener, an American mathematician, was a precocious man who went to college at the age of 11. He was invited to give lectures at Tsinghua University in China from 1935 to 1936.

Once, he attended an important meeting, and his young face was eye-catching. So someone asked his age, and he replied: "The cube of my age is a 4-digit number. The 4th power of my age is a 6-digit number. These 10 numbers just contain the 10 numbers from 0 to 9, each Both occur exactly once."

Please calculate how young he was then.

hint:

First use /10 and %10 to take out the numbers on each digit, and then judge whether they are equal

Analysis:
Let age be x;  

The cube of age is a 4-digit number: x^3 is a 4-digit number
(age greater than 10 and less than 22)

The 4th power of age is a 6-digit number: x^4 is a 6-digit number
(age greater than 18)

The 10 numbers contain exactly 10 numbers from 0 to 9, and each of them appears exactly once.
Among the above four-digit and six-digit numbers, 1-9 only appears once

Find age x; between 18 and 22

public class _1_11 {
    public static void main(String[] args) {
        int c[] = new int[]{0,1,2,3,4,5,6,7,8,9};
        int d[] = new int[]{0,0,0,0,0,0,0,0,0,0};
        int i,count=0;
        for( i=18;i<22;i++)
        {
            int a=(int)Math.pow(i,3);
            int b=(int)Math.pow(i,4);
            if(10000>a && a>1000 && b>100000 && b<1000000)
            {
                while(a>0)
                {
                    for(int j=0;j<10;j++)
                        if(a%10==c[j])
                            d[j]+=1;
                    a=a/10;
                }
                while(b>0)
                    {
                        for(int j=0;j<10;j++)
                            if(b%10==c[j])
                                d[j]+=1;
                        b=b/10;
                    }
                for(int j=0;j<10;j++)
                {
                    if(d[j]==1)
                        count++;
                    if(count==10)
                        System.out.println(i);
                }
                count=0;
            }
        }
    }
}

 

Guess you like

Origin blog.csdn.net/weixin_64428129/article/details/126173320