题目链接

 

Java程序

package projecteuler51to60;

import java.math.BigInteger;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet; class level56{
void solve0(){
int maxsum=0;
for(int a=2;a<100;a++){
for(int b=2;b<100;b++){
BigInteger bigNum = BigInteger.valueOf(a).pow(b);
maxsum=Math.max(digitSum(bigNum), maxsum);
// System.out.println(maxsum);
}
}
System.out.println(maxsum);
}
private int digitSum(BigInteger n) {
int sum = 0;
String s = n.toString();
for (int i = 0; i < s.length(); i++)
sum += s.charAt(i) - '0';
return sum;
}
int sumDigits(BigInteger num){
int sum=0;
BigInteger ten = BigInteger.valueOf(10);
while(num.equals(0)){
sum+=(num.mod(ten)).intValue();
num = num.divide(ten);
}
return sum;
} }
public class Problem56 { public static void main(String[] args){
long begin= System.currentTimeMillis();
new level56().solve0();
long end = System.currentTimeMillis();
long Time = end - begin;
System.out.println("Time:"+Time/1000+"s"+Time%1000+"ms");
} }

由于上面程序写的时间有点长了,不做过多分析,只贴程序

欧拉工程第56题:Powerful digit sum的更多相关文章

  1. 欧拉工程第74题:Digit factorial chains

    题目链接:https://projecteuler.net/problem=74 数字145有一个著名的性质:其所有位上数字的阶乘和等于它本身. 1! + 4! + 5! = 1 + 24 + 120 ...

  2. 欧拉工程第69题:Totient maximum

    题目链接 欧拉函数φ(n)(有时也叫做phi函数)可以用来计算小于n 的数字中与n互质的数字的个数. 当n小于1,000,000时候,n/φ(n)最大值时候的n. 欧拉函数维基百科链接 这里的是p是n ...

  3. 欧拉工程第70题:Totient permutation

    题目链接 和上面几题差不多的 Euler's Totient function, φ(n) [sometimes called the phi function]:小于等于n的数并且和n是互质的数的个 ...

  4. 欧拉工程第63题:Powerful digit counts

    题目链接 The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit number, 134217728=8 ...

  5. 欧拉工程第51题:Prime digit replacements

    题目链接 题目: 通过置换*3的第一位得到的9个数中,有六个是质数:13,23,43,53,73和83. 通过用同样的数字置换56**3的第三位和第四位,这个五位数是第一个能够得到七个质数的数字,得到 ...

  6. 欧拉工程第67题:Maximum path sum II

    By starting at the top of the triangle below and moving to adjacent numbers on the row below, the ma ...

  7. 欧拉工程第66题:Diophantine equation

    题目链接 脑补知识:佩尔方差 上面说的貌似很明白,最小的i,对应最小的解 然而我理解成,一个循环的解了,然后就是搞不对,后来,仔细看+手工推导发现了问题.i从0开始变量,知道第一个满足等式的解就是最小 ...

  8. 欧拉工程第65题:Convergents of e

    题目链接 现在做这个题目真是千万只草泥马在心中路过 这个与上面一题差不多 这个题目是求e的第100个分数表达式中分子的各位数之和 What is most surprising is that the ...

  9. 欧拉工程第55题:Lychrel numbers

    package projecteuler51to60; import java.math.BigInteger; import java.util.Iterator; import java.util ...

随机推荐

  1. iOS8 蓝牙设备的重连接(retrieve) Swift实现

    今天App写到了蓝牙重连的阶段,以前针对sdk 6.0写的代码,蓝牙设备的回复是通过 - (void)retrievePeripherals:(NSArray *)peripheralUUIDs 然后 ...

  2. 检测到有潜在危险的 Request.Form 值。 说明: ASP.NET 在请求中检测到包含潜在危险的数据

    在请求方法的顶部添加        [ValidateInput(false)]就OK了 从客户端(Content=" sdfdddd ...")中检测到有潜在危险的 Reques ...

  3. Sliverlight Slide 的左右滑动

    private void btnPrev_Click(object sender, RoutedEventArgs e) { scrollRule = (scrollRule-) >= ?(sc ...

  4. java数据结构和算法------希尔排序

    package iYou.neugle.sort; public class Shell_sort { public static void ShellSort(double[] array) { i ...

  5. SVN补充

    为什么使用SVN? 1.需求1:备份,以防电脑死机断电等 2.需求2:代码还原,代码不管你改成什么样都可以找到某一段的版本 3.需求3:协同修改,下载修改同一个文件,防止被相互覆盖 4.需求4:多版本 ...

  6. php file_put_contents() 写入回车

    PHP file_put_contents() 函数是一次性向文件写入字符串或追加字符串内容的最合适选择. file_put_contents() file_put_contents() 函数用于把字 ...

  7. javascript 对象数组排序

    参考地址:http://blog.csdn.net/kavensu/article/details/17851329

  8. 对git的初步认识

    虽然经常听说博客,但是却是第一次用.就像,虽然经常见电脑,但是却第一次接触软件.对于git也是一样,从来没听过,更不了解. 因为自己私下也没有去过多的了解,所以对于git只有一些有关书面资料的很片面的 ...

  9. Visual Studio 2013

    1.How to hide reference counts in VS2013? Tools--> Options --> Text Editor --> All Language ...

  10. zoj 2314 Reactor Cooling 网络流

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1314 The terrorist group leaded by a ...