Codewars-Kata:Common Denominators问题

该博客介绍了如何解决Codewars上的'Common Denominators'问题,主要关注正整数的素因数分解。作者提出使用Map集合来存储并计数素因子,通过这种方法找到素数的分解,并以规定的字符串格式返回结果。
摘要由CSDN通过智能技术生成

Primes in numbers

题目

image-20211119164040986

  • Title

    Given a positive number n > 1 find the prime factor decomposition of n. The result will be a string with the following form :

     "(p1**n1)(p2**n2)...(pk**nk)"
    

    with the p(i) in increasing order and n(i) empty if n(i) is 1.

    Example: n = 86240 should return "(2**5)(5)(7**2)(11)"
    

解题思路

  1. 用map集合来计数,如果是他的因子,则存入map集合
  2. 最后进行输出

代码

public static String factors(int n) {
    String str = "";
    Map<Integ
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值