HDOJ 1164 Eddy's research I(拆分成素数因子)

简介: HDOJ 1164 Eddy's research I(拆分成素数因子)

Problem Description

Eddy’s interest is very extensive, recently he is interested in prime number. Eddy discover the all number owned can be divided into the multiply of prime number, but he can’t write program, so Eddy has to ask intelligent you to help him, he asks you to write a program which can do the number to divided into the multiply of prime number factor .


Input

The input will contain a number 1 < x<= 65535 per line representing the number of elements of the set.


Output

You have to print a line in the output for each entry with the answer to the previous question.


Sample Input

11

9412


Sample Output

11

2*2*13*181


这个题的数据很水,不用判断素数也能过的。

直接for循环遍历几次2-n就可以了。

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt();
            for(int i=2;i*i<=n;i++)//如果一个数字不素数的话并且可以被两个或者两个以上的数字的乘积组成的话,那么它的组成部分一定小于等于该数的开根号.
            {
                if(n%i==0)
                {
                    n=n/i;
                    System.out.printf("%d*",i);
                    i=1;
                }
            }
            System.out.printf("%d",n);
            System.out.println();
        }
    }
}
目录
相关文章
|
5月前
|
人工智能 算法 BI
D - Silver Cow Party——POJ3268(连续用两次Dijkstra算法)
D - Silver Cow Party——POJ3268(连续用两次Dijkstra算法)
|
12月前
|
算法
华为机试HJ82:将真分数分解为埃及分数
华为机试HJ82:将真分数分解为埃及分数
|
Java Shell
Codeforces Round #746 (Div. 2) D - Hemose in ICPC ?(交互 二分 欧拉序)
Codeforces Round #746 (Div. 2) D - Hemose in ICPC ?(交互 二分 欧拉序)
151 0
|
机器学习/深度学习
Codeforces1499——C. Minimum Grid Path(思维+分奇偶+贪心)
Codeforces1499——C. Minimum Grid Path(思维+分奇偶+贪心)
88 0
|
人工智能 vr&ar
SPOJ - COT Count on a tree(主席树 LCA)
SPOJ - COT Count on a tree(主席树 LCA)
88 0
|
机器学习/深度学习 人工智能 算法
CF1446D Frequency Problem(思维 前缀和 根号分治 双指针)
CF1446D Frequency Problem(思维 前缀和 根号分治 双指针)
85 0
|
机器学习/深度学习
UPC-最优分解问题(贪心)
UPC-最优分解问题(贪心)
74 0
[USACO | UPC] Liars and Truth Tellers | 拓展域并查集
题目描述 After spending so much time around his cows, Farmer John has started to understand their language. Moreover, he notices that among his N cows (2 ≤ N ≤ 1000 ), some always tell the truth while others always lie.
123 0
|
机器学习/深度学习 物联网
[Codeforces 1586] Omkar and Determination | 思维前缀和
题意 给定一个n ∗ m 的方格,在这个方格中有一些点被标记为′ . ′ 说明这个点是没有障碍的,而′ X ′ 代表这个点是有障碍的,不能通过这个点,对于每个点,只能向上或者是向左走。如所说有的′ . ′ 点不能走出去,那么这样的′ . ′ 点就不是e x i t a b l e exitable 问题是:给定一个矩阵里面所有的 exitable点,如果给出的矩阵能够唯一确定,就是YES,否则输出 NO 所以问题就变成了给定的矩阵范围中有没有是′ . ′但是不能够 exitable的点,如果有就无法唯一确定(YES),反之就可以唯一确定(NO) 数据范围太大,可以开 vector 来模拟二维数
581 0
【1150】Travelling Salesman Problem (25分)【图论】
【1150】Travelling Salesman Problem (25分)【图论】 【1150】Travelling Salesman Problem (25分)【图论】
91 0