codewars025: Playing with digits

package codewars;
//--https://www.codewars.com/kata/5552101f47fc5178b1000050/train/java
public class DigPow{
  public static long digPow(){
    String str = String.valueOf(n);
    long sum = 0;
    for(int i = 0; i < str.length(); i++){
      sum += (long) Math.pow(Integer.valueOf(String.valueOf(str.charAt(i))),p + i);
    }
    if(sum % n == 0){
      return sum / n;
    }
    return -1;
  }
}
相關文章
相關標籤/搜索