题目链接

 

Java程序

  1. package projecteuler51to60;
  2.  
  3. import java.math.BigInteger;
  4. import java.util.Iterator;
  5. import java.util.Set;
  6. import java.util.TreeSet;
  7.  
  8. class level56{
  9. void solve0(){
  10. int maxsum=0;
  11. for(int a=2;a<100;a++){
  12. for(int b=2;b<100;b++){
  13. BigInteger bigNum = BigInteger.valueOf(a).pow(b);
  14. maxsum=Math.max(digitSum(bigNum), maxsum);
  15. // System.out.println(maxsum);
  16. }
  17. }
  18. System.out.println(maxsum);
  19. }
  20. private int digitSum(BigInteger n) {
  21. int sum = 0;
  22. String s = n.toString();
  23. for (int i = 0; i < s.length(); i++)
  24. sum += s.charAt(i) - '0';
  25. return sum;
  26. }
  27. int sumDigits(BigInteger num){
  28. int sum=0;
  29. BigInteger ten = BigInteger.valueOf(10);
  30. while(num.equals(0)){
  31. sum+=(num.mod(ten)).intValue();
  32. num = num.divide(ten);
  33. }
  34. return sum;
  35. }
  36.  
  37. }
  38. public class Problem56 {
  39.  
  40. public static void main(String[] args){
  41. long begin= System.currentTimeMillis();
  42. new level56().solve0();
  43. long end = System.currentTimeMillis();
  44. long Time = end - begin;
  45. System.out.println("Time:"+Time/1000+"s"+Time%1000+"ms");
  46. }
  47.  
  48. }

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

欧拉工程第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. 通过WebBrowser取得AJAX后的网页

    通常情况下通过WebBrowser的文档加载完成事件DocumentCompleted中进行判断 if (_WebBrowder.ReadyState == WebBrowserReadyState. ...

  2. exception -----> Typedefs & Classes

    #include <exception> Typedefs exception_ptr 一种类型,描述了一个指向异常的指针 terminate_handler 一种类型,描述了一个适合作为 ...

  3. ios 唯一标示符

    大家知道苹果每部 iOS 设备都有一个 UDID,它就像设备的身份证一样,记录着设备的名称.类型甚至一些关于用户的私人信息.通常情况下,UDID 的一个最大功能就是帮助广告发布商向特定用户推送定向广告 ...

  4. 利用FormsAuthentication.RedirectFromLoginPage进行身份验证

    web.config中: <authentication>节 格式: <authentication mode="Forms">    //I.Window ...

  5. 基于PBOC电子钱包的消费过程详解

    智能卡金融行业应用电子钱包的消费交易流程,开发人员可参考 首先终端和卡片有一个共同的密钥叫做消费密钥:PurchKey (针对每种特定的交易,比如,圈存,消费,都有特定的密钥与之对应) 假设Purch ...

  6. VBS数组函数学习实例分析

    Array 函数 返回包含数组的Variant. Array(arglist) 参数:arglist是赋给包含在Variant中的数组元素的值的列表(用逗号分隔).如果没有指定此参数,则将会创建零长度 ...

  7. C# Redis

    概念 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,和Memcached类似,它支持存储的value类型相对更多,包括string( ...

  8. bzoj 3295 树套树

    比较裸,可以有好多的优化,比如根本没有删除的点没有加在树套树中的必要,预处理 出来每个不会被删除的值可以减少不少时间,也可以写成树状数组套平衡树,都会快很多 /******************** ...

  9. 新浪微博之XSS蠕虫脚本源码讲解

    主要是因为新浪的广场页面有几个链接对输入参数过滤不严导致的反射性XSS.======================================== 微博XSS漏洞点 weibo.com/pub/ ...

  10. javascript设计模式-迭代器模式(Iterator)

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...