codewars-014: k-Primes

https://www.codewars.com/kata/k-primes/train/javajava

// https://www.codewars.com/kata/k-primes/train/java
package codewars;
class PrimeConsec{
  public static int primeDecomp(long n){
    int i=2;
    int count=0;
    while(n >= i){
      if(n % i == 0){
        n = n / i;
        count++;
      }else{
        i++;
      }
    }
    return count;
  }
  public static int consecKprimes(int k, long[] arr){
    int[] factor = new int[arr.length];
    int count = 0;
    for(int i=0; i < arr.length; i++){
      if(factor[i] == k && factor[i] == factor[i + 1]){
        count++;
      }
    }
    return count;
  }
}
本站公眾號
   歡迎關注本站公眾號,獲取更多信息