欧拉工程第56题:Powerful digit sum
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的更多相关文章
- 欧拉工程第74题:Digit factorial chains
题目链接:https://projecteuler.net/problem=74 数字145有一个著名的性质:其所有位上数字的阶乘和等于它本身. 1! + 4! + 5! = 1 + 24 + 120 ...
- 欧拉工程第69题:Totient maximum
题目链接 欧拉函数φ(n)(有时也叫做phi函数)可以用来计算小于n 的数字中与n互质的数字的个数. 当n小于1,000,000时候,n/φ(n)最大值时候的n. 欧拉函数维基百科链接 这里的是p是n ...
- 欧拉工程第70题:Totient permutation
题目链接 和上面几题差不多的 Euler's Totient function, φ(n) [sometimes called the phi function]:小于等于n的数并且和n是互质的数的个 ...
- 欧拉工程第63题:Powerful digit counts
题目链接 The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit number, 134217728=8 ...
- 欧拉工程第51题:Prime digit replacements
题目链接 题目: 通过置换*3的第一位得到的9个数中,有六个是质数:13,23,43,53,73和83. 通过用同样的数字置换56**3的第三位和第四位,这个五位数是第一个能够得到七个质数的数字,得到 ...
- 欧拉工程第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 ...
- 欧拉工程第66题:Diophantine equation
题目链接 脑补知识:佩尔方差 上面说的貌似很明白,最小的i,对应最小的解 然而我理解成,一个循环的解了,然后就是搞不对,后来,仔细看+手工推导发现了问题.i从0开始变量,知道第一个满足等式的解就是最小 ...
- 欧拉工程第65题:Convergents of e
题目链接 现在做这个题目真是千万只草泥马在心中路过 这个与上面一题差不多 这个题目是求e的第100个分数表达式中分子的各位数之和 What is most surprising is that the ...
- 欧拉工程第55题:Lychrel numbers
package projecteuler51to60; import java.math.BigInteger; import java.util.Iterator; import java.util ...
随机推荐
- 通过WebBrowser取得AJAX后的网页
通常情况下通过WebBrowser的文档加载完成事件DocumentCompleted中进行判断 if (_WebBrowder.ReadyState == WebBrowserReadyState. ...
- exception -----> Typedefs & Classes
#include <exception> Typedefs exception_ptr 一种类型,描述了一个指向异常的指针 terminate_handler 一种类型,描述了一个适合作为 ...
- ios 唯一标示符
大家知道苹果每部 iOS 设备都有一个 UDID,它就像设备的身份证一样,记录着设备的名称.类型甚至一些关于用户的私人信息.通常情况下,UDID 的一个最大功能就是帮助广告发布商向特定用户推送定向广告 ...
- 利用FormsAuthentication.RedirectFromLoginPage进行身份验证
web.config中: <authentication>节 格式: <authentication mode="Forms"> //I.Window ...
- 基于PBOC电子钱包的消费过程详解
智能卡金融行业应用电子钱包的消费交易流程,开发人员可参考 首先终端和卡片有一个共同的密钥叫做消费密钥:PurchKey (针对每种特定的交易,比如,圈存,消费,都有特定的密钥与之对应) 假设Purch ...
- VBS数组函数学习实例分析
Array 函数 返回包含数组的Variant. Array(arglist) 参数:arglist是赋给包含在Variant中的数组元素的值的列表(用逗号分隔).如果没有指定此参数,则将会创建零长度 ...
- C# Redis
概念 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,和Memcached类似,它支持存储的value类型相对更多,包括string( ...
- bzoj 3295 树套树
比较裸,可以有好多的优化,比如根本没有删除的点没有加在树套树中的必要,预处理 出来每个不会被删除的值可以减少不少时间,也可以写成树状数组套平衡树,都会快很多 /******************** ...
- 新浪微博之XSS蠕虫脚本源码讲解
主要是因为新浪的广场页面有几个链接对输入参数过滤不严导致的反射性XSS.======================================== 微博XSS漏洞点 weibo.com/pub/ ...
- javascript设计模式-迭代器模式(Iterator)
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...