solution.java 887 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static boolean judge(int x) {
        int a = x * x * x;
        int b = x * x * x * x;
        boolean vis[] = new boolean[10];
        if (a < 1000 || a > 9999)
            return false;
        if (b < 100000 || b > 999999)
            return false;
        while (a > 0) {
            vis[a % 10] = true;
            a /= 10;
        }
        while (b > 0) {
            vis[b % 10] = true;
            b /= 10;
        }
        for (int i = 0; i < 10; i++)
            if (!vis[i])
                return false;
        return true;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        for (int i = 1; i <= 1000; i++) {
            if (judge(i)) {
                System.out.println(i);
                break;
            }
        }
    }
}