# [kata] Playing with digits

+关注继续查看
package kata_011;

/**
* Some numbers have funny properties. For example:
*
* 89 --> 8¹ + 9² = 89 * 1
*
* 695 --> 6² + 9³ + 5⁴= 1390 = 695 * 2
*
* 46288 --> 4³ + 6⁴+ 2⁵ + 8⁶ + 8⁷ = 2360688 = 46288 * 51
*
* Given a positive integer n written as abcd... (a, b, c, d... being digits)
* and a positive integer p we want to find a positive integer k, if it exists,
* such as the sum of the digits of n taken to the successive powers of p is
* equal to k * n. In other words:
*
* Is there an integer k such as : (a ^ p + b ^ (p+1) + c ^(p+2) + d ^ (p+3) + ...) = n * k
*
* If it is the case we will return k, if not return -1.
*
* Note: n, p will always be given as strictly positive integers.
*
* digPow(89, 1) should return 1 since 8¹ + 9² = 89 = 89 * 1 digPow(92, 1)
* should return -1 since there is no k such as 9¹ + 2² equals 92 * k
* digPow(695, 2) should return 2 since 6² + 9³ + 5⁴= 1390 = 695 * 2
* digPow(46288, 3) should return 51 since 4³ + 6⁴+ 2⁵ + 8⁶ + 8⁷ = 2360688 = 46288 * 51
*
* @author SeeClanUkyo
*
*/
public class DigPow {
public static void main(String[] args) {

System.out.println(digPow(46288, 3));
}

public static long digPow(int n, int p) {
if (n > 0) {
String nstr = n + "";
int nlen = nstr.length();

long sum = 0;
for (int i = 0; i < nlen; i++) {
sum += Math.pow(Integer.parseInt(nstr.substring(i, i + 1)), (p + i));
if (sum % n == 0) {
return sum / n;
}
}

}
return -1;
}
}

0 0

0 0
LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之三：两次优化

0 0
SLA By Short Brain

0 0
High&NewTech：L&L / GCP BOOTH at CES 2019 - January 8-11, 2019 - Westgate Convention Center Las Vegas
High&NewTech：L&L / GCP BOOTH at CES 2019 - January 8-11, 2019 - Westgate Convention Center Las Vegas
0 0

0 0
Elastic Training Operator: Kubernetes 上运行弹性深度学习训练任务
## 背景 由于云计算在资源成本和弹性扩容方面的天然优势，越来越多客户愿意在云上构建AI系统，而以容器，Kubernetes 为代表的云原生技术，已经成为释放云价值的最短路径， 在云上基于Kubernetes 构建AI平台已经成为趋势。 当面临较复杂的模型训练或者数据量大时，单机的计算能力往往无法满足算力要求。 通过使用 阿里的AiACC 或者社区的 [horovod](https:/
0 0
kubernetes1.4 基础篇：Learn Kubernetes 1.4 by 6 steps（1）：概要

854 0
mirantis fuel

1743 0