欧拉工程第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 ...
随机推荐
- [转]AngularJS: 使用Scope时的6个陷阱
在使用AngularJS中的scope时,会有6个主要陷阱.如果你理解AngularJS背后的概念的话,这6个点其实非常的简单.但是在具体讲述这6个陷阱之前我们先要讲两个其它的概念. 概念1: 双向数 ...
- Learning note for Binding and validation
Summary of my learning note for WPF Binding Binding to DataSet. when we want to add new record, we s ...
- VS 与 SQLite数据库 连接
SQLite并没有一次性做到位,只有下载这些东西是不能放在vs2010中并马上使用的,下载下来的文件中有sqlite3.c/h/dll/def,还是不够用的.我们需要的sqlite3.lib文件并不在 ...
- [shell基础]——数组
数组赋值 1. 逐个数组元素赋值 # array[0]=11 # array[1]=22 # array[2]=33 # echo ${array[@]} 11 22 33 33 2. array( ...
- Leetcode-Construct Binary Tree from inorder and preorder travesal
Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that ...
- Python2.x与3.x版本区别
Python的3.0版本,常被称为Python 3000,或简称Py3k.相对于Python的早期版本,这是一个较大的升级. 为了不带入过多的累赘,Python 3.0在设计的时候没有考虑向下相容 ...
- Class.forName("com.mysql.jdbc.Driver");的作用
对于大的项目当然我们都已经有了原有基本框架,但是对于一些新的技术探讨的时候,我们还是直接调用Class.forName("com.mysql.jdbc.Driver")连接数据库进 ...
- discuz之同步登入
前言 首先感谢dozer学长吧UCenter翻译成C# 博客地址----------->http://www.dozer.cc/ 其次感谢群友快乐々止境同学的热心指导,虽然萍水相逢但让我 ...
- poj 1422 Air Raid 最少路径覆盖
题目链接:http://poj.org/problem?id=1422 Consider a town where all the streets are one-way and each stree ...
- Hibernate O/R Mapping模拟
作为SSH中的重要一环,有必要理解一下Hibernate对 O/R Mapping的实现. 主要利用java的反射机制来得到完整的SQL语句. 准备工作: 1. Object Student实体类: ...