猜年龄

美国数学家维纳(N.Wiener)智力早熟,11岁就上了大学。他曾在1935~1936年应邀来中国清华大学讲学。一次,他参加某个重要会议,年轻的脸孔引人注目。于是有人询问他的年龄,他回答说:“我年龄的立方是个4位数。我年龄的4次方是个6位数。这10个数字正好包含了从0到9这10个数字,每个都恰好出现1次。" 请你推算一下,他当时到底有多年轻。

public class Main {
    public static void main(String[] args) {
        for(int i=Math.round((int)Math.pow(1000,1/3.0));i<Math.pow(10000,1/3.0);i++){
            if(Math.pow(i,4)>Math.pow(10,5)&&Math.pow(i,4)<Math.pow(10,6)){
                String chars=((int)Math.pow(i,3)+""+(int)Math.pow(i,4));
                Set<Character> set = new HashSet<>();
                char[] s = chars.toCharArray();
                for(char c:s) {
                    set.add(c);
                }
                if(set.size()==10){
                    System.out.print(i);
                }
            }
        }
    }
}   

 

posted @ 2021-11-13 09:06  xuxianglu  阅读(44)  评论(0编辑  收藏  举报