题解 | #质数因子#

质数因子

https://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607

import java.io.IOException;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
        long zhi = sc.nextInt();
        long k1 =zhi;
        long j = 1;
        long k2 = (long) Math.sqrt(zhi);
            for(long i = 2; i < k2;i++){
                long result = zhi%zhi;
                long result1 = zhi/zhi;
                while(result == 0){
                    result = zhi%i;


                    if(result == 0) {
                        result1 = zhi/i;
                        zhi = result1;
                        System.out.print(i);
                        System.out.print(" ");
                        j=j*i;
                    }
                }


            }
            if(k1 == k2*k2){
                System.out.print(k2 +" " + k2);
                return;
            }
            if(k1 > j){
                System.out.println(k1/j);
            }
        
        }

    }
}
#华为OD机考#
全部评论

相关推荐

不愿透露姓名的神秘牛友
10-04 05:12
kalistar:简历留六个字,北京大学(本科),黑体加粗,看看哪个hr不长眼敢碰瓷我们北大✌
点赞 评论 收藏
分享
大野鸡:其实就是量,但是时间有限,1000题只要不是全中等简单,简单中等困难1-2-1,大概能打打比赛了(前20%),10000题就是下一个灵神
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务