栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

因子个数公式(如何求一个数的所有因子)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

因子个数公式(如何求一个数的所有因子)

普通做法

public class Main {
    static int j = 0;
    static int[] ssss = new int[10001];
    public static void main(String[] args) {
        sn(30);
        for (int i = 0; i < j; i++) {
            System.out.println(ssss[i]);
            
        }
    }
    
    public static void sn(int s){
        for(int i = 1;i <= s/i;i++) {
            if (s % i == 0) {
                ssss[j++] = i;
                if (i * i != s)
                    ssss[j++] = s / i;
            }
        }
    }
}

唯一分解定理

import java.util.Scanner;

public class Main {
    static int index = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] su = new int[100001];   //素数表
        int[] sus = new int[100001]; //在唯一分解定理中出现的素数
        int[] ci = new int[100001]; //各个素数的指数
        int ind = 0;
        sushu(su, n);
        int c = n;
        boolean flag = false;
        //唯一分解定理 求出 x = p1^a1 * p2^a2 .... 的形式
        for (int i = 0; i < index; i++) {
            if (c == 1) {
                break;
            }
            while (c % su[i] == 0) {
                c /= su[i];
                sus[ind] = su[i];
                ci[ind]++;
                flag = true;
            }
            if (flag) {
                ind++;
            }
            flag = false;
        }
        int ans = 1;
        for(int i = 0;i
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/773478.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号