zoukankan      html  css  js  c++  java
  • Java实现 蓝桥杯VIP 算法提高 质因数2

    算法提高 质因数2
    时间限制:1.0s 内存限制:256.0MB
      将一个正整数N(1<N<32768)分解质因数,把质因数按从小到大的顺序输出。最后输出质因数的个数。
    输入格式
      一行,一个正整数
    输出格式
      两行,第一行为用空格分开的质因数
      第二行为质因数的个数
    样例输入
    66
    样例输出
    2 3 113
    样例输入
    90
    样例输出
    2 3 3 5
    4
    样例输入
    37
    样例输出
    37
    1

    import java.util.Scanner;
    
    
    public class 质因数2 {
    	public static void main(String[] args) {
    		//质因数2
    		Scanner sca = new Scanner(System.in);
    		int n = sca.nextInt();
    		int i = 2,count=0;
    		String s = "";
    		while (n != 1) {
    			while (n%i == 0){
    				n /= i;
    				s += i+" ";
    				count++;
    			}
    			i++;
    		}
    		System.out.println(s);
    		System.out.println(count);
    	}
    
    
    }
    
    
  • 相关阅读:
    卡特兰数
    混合运算改进(代码)
    典型用户和场景
    混合运算
    四则运算
    计算
    感想
    git
    附加导航 affix,side--toolbar(可结合博客园使用~)
    对python-rrdtool模块的浅研究。
  • 原文地址:https://www.cnblogs.com/a1439775520/p/12948394.html
Copyright © 2011-2022 走看看