欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

HDU1164 Eddy's research I (试除法)

程序员文章站 2022-07-05 16:59:49
...

Problem

试除法
HDU1164 Eddy's research I (试除法)
根据题意处理一些边边角角的问题即可提交。

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static int N = 20, k;
    static int prime[];

    public static void main(String[] args) throws IOException {

        while (true) {
            String s = br.readLine();
            if (s == null) break;
            int x = Integer.parseInt(s);
            divide(x);
            for (int i = 0; i < k - 1; i++) System.out.print(prime[i] + "*");
            System.out.println(prime[k - 1]);
        }

    }

    public static void divide(int x) {
        prime = new int[N];
        k = 0;
        for (int i = 2; i <= x / i; i++) {
            if (x % i == 0) {
                prime[k++] = i;
                x /= i;
                i--;
            }
        }
        prime[k++] = x;
        Arrays.sort(prime, 0, k);
    }

}

相关标签: 数学算法