- 浏览: 143299 次
- 性别:
- 来自: 01
文章分类
最新评论
-
kingj:
将if(node.RightTree==null||node. ...
在二元树中找出和为某一值的所有路径 -
kingj:
非递归的算法在下面这种情况下会有问题 ...
在二元树中找出和为某一值的所有路径 -
houxinbin:
DateUtil.getTimestampFromGregor ...
使用JFreeChart显示 Java 虚拟机中的空闲内存量 -
坏小子46110:
我在build comm.js的时候有个这个异常 不知道怎么解 ...
使用Java实现登陆WebQQ(带源码) -
to_zoe_yang:
公子_小王 写道怎么下载不下来呢? 估计TX现在肯定改接口了都 ...
使用Java实现登陆WebQQ(带源码)
问题描述:
The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order, but it also has a rather interesting sub-string divisibility property.
Let d1 be the 1st digit, d2 be the 2nd digit, and so on. In this way, we note the following:
- d2d3d4=406 is divisible by 2
- d3d4d5=063 is divisible by 3
- d4d5d6=635 is divisible by 5
- d5d6d7=357 is divisible by 7
- d6d7d8=572 is divisible by 11
- d7d8d9=728 is divisible by 13
- d8d9d10=289 is divisible by 17
Find the sum of all 0 to 9 pandigital numbers with this property.
解决问题:
package projecteuler; import java.util.Arrays; public class Problem43 { public static final Long UP = 9876543210L; public static final int START = 123; public static final int HIGH = 9; public static int[] Number = new int[9]; public static final int[] Element = {0,1,2,3,4,5,6,7,8,9}; public static final int[] prime = {2,3,5,7,11,13,17}; public static long sum = 0; public static long Factorial(int number){ long r = 1; for(int i=number; i>1; i--){ r *= i; } return r; } public static long ai_find(int Last){ Arrays.fill(Number, 0); int remain = Last-1; int high = HIGH; int posititon = 0; while(remain!=0){ long value = Factorial(high); long num = 0; if(remain>=value){ num = remain/value; remain -= value*num; Number[posititon] = (int)num; }else{ Number[posititon] = 0; } // System.out.println("Position:"+posititon+",value:"+value+",num:"+num+",remain:"+remain); posititon++; high--; } boolean[] matcher = new boolean[10]; Arrays.fill(matcher, false); String str = ""; long value = 0; for(int i=0;i<Number.length; i++){ int index = 0; for(int j=0; j<matcher.length; j++){ if(index==Number[i]&&!matcher[j]){ str = str + j; value = value*10 + j; matcher[j] = true; break; } if(!matcher[j]){ index++; } } } for(int i=0; i<matcher.length; i++){ if(!matcher[i]){ value = value*10 + i; str = str + i; } } // System.out.println(str); // System.out.println("i:"+value); return value; } public static void find(int level, boolean[] elements, long result) { if (level == 0) { if(IsNumber(result)){ sum += result; } // System.out.println(result); return; } for (int i = 0; i < elements.length; i++) { if (elements[i]) { elements[i] = false; long tmp = result; result = result * 10 + i; find(level - 1, elements, result); elements[i] = true; result = tmp; } // System.out.println("Level:"+level+",i:"+i+",Result:"+result); } } public static boolean IsPandigital(long number){ boolean[] elements = new boolean[10]; Arrays.fill(elements, true); if(number<=987654321){ for(int i=1; i<10;i++){ int cur = (int)number%10; if(!elements[cur]){ return false; } number = number/10; elements[cur] = false; } return true; }else{ for(int i=0; i<10;i++){ int cur = (int)number%10; if(!elements[cur]){ return false; } number = number/10; elements[cur] = false; } return true; } } public static boolean IsNumber(long number){ long init = number; int divide = 1000000; if(number<=987654321){ for(int i=0; i<prime.length; i++){ long value = number/divide; if(value%prime[i]!=0){ return false; } number = number %10; divide = divide/10; } return true; }else{ number = number%1000000000; // System.out.println("number:"+number); for(int i=0; i<prime.length; i++){ long value = number/divide; // System.out.println(value); if(value%prime[i]!=0){ return false; } number = number%(divide*100); divide = divide/10; } return true; } } public static void main(String[] args){ int result = 0; boolean[] elements= new boolean [10]; Arrays.fill(elements, true); find(10, elements, result); System.out.println(IsNumber(1406357289)); System.out.println(sum); } }
发表评论
-
Problem 52
2011-09-07 19:37 880问题描述: It can be seen that th ... -
Problem 51
2011-09-06 19:46 966问题描述: By replacing the ... -
Problem 50
2011-09-03 14:53 921问题描述: The prime 41, can b ... -
Problem 49
2011-08-28 15:34 918问题描述: The arithmetic seq ... -
Problem 47
2011-08-27 16:10 545问题描述: The first two co ... -
Problem 46
2011-08-26 18:08 581问题描述: It was proposed by Chr ... -
Problem 45
2011-08-25 18:24 953问题描述: Triangle, pentagona ... -
Problem 42
2011-08-23 09:18 858问题描述: The nth term of the se ... -
Problem 41
2011-08-19 15:08 717问题描述: We shall say that an n ... -
Problem 40
2011-08-18 14:27 784算法描述: An irrational decimal ... -
Problem 39
2011-08-17 15:28 870问题描述: If p is the perimeter ... -
Problem 38
2011-08-17 15:27 761问题描述: Take the number 192 an ... -
Problem 37
2011-08-17 15:26 756问题描述: The number 3797 has an ... -
Problem 36
2011-08-17 15:23 816问题描述: The decimal number, 58 ... -
Problem 35
2011-08-17 15:22 722问题描述: The number, 197, is ca ... -
Problem 34
2011-08-17 15:20 795问题描述: 145 is a curious numbe ... -
Problem 33
2011-08-17 15:18 767问题描述: The fraction 49/98 is ... -
Problem 32
2011-08-17 15:17 894问题描述: We shall say that an n ... -
Problem 30
2011-08-17 15:11 495问题描述: Surprisingly there ... -
Problem 29
2011-08-17 15:09 665问题描述: Consider all integer c ...
相关推荐
"problem43-main"可能是指一个主要的程序文件或者是一个包含解决问题43的代码的文件。 如果“问题43”涉及的是Python基础,可能与变量、条件语句(if-else)、循环(for和while)、函数定义、列表、字典、集合或...
该项目是一款基于Go语言的Container Problem Detect System异常检测器,源码包含2261个文件,涵盖1823个Go源文件、98个Markdown文件、51个Shell脚本文件、43个Git忽略文件、31个YAML配置文件、18个模板文件、14个...
Andrew Stankevich Contest 45是由Artem Vasilev和Pavel Krotkov两位来自ITMO大学的参赛者在2016年4月举办的北京大学集训营中进行的问题分析。这次竞赛包含了多个具体的算法问题,并针对每个问题给出了详细的解决...
离线安装包,亲测可用
离线安装包,亲测可用
离线安装包,亲测可用
43 54 ``` #### 解题思路与算法设计 **1. 最小得分** 为了求解最小得分,我们需要找到一种策略,使得每次合并都尽可能减小当前合并的得分。直观上讲,我们应该优先合并石子数量较少的两堆,因为这样可以减少每次...
为了优化归并排序的运行时间,建议在输入规模小于或等于 43 时改用插入排序。 ### 知识点三:不同函数的增长率比较 文档中还给出了几种常见函数的增长率比较,这有助于理解不同算法的时间复杂度。例如,对于不同...
The effect of time of day on problem solving and classroom behavior Psychology in ihe Schools Volume 20....The 43 participating pupils were observed with Stonybrook Observation Code
Problem Runtime Mem Usage Level 28毫秒( 93.73% ) 13.4 MB( 79.11% ) 简单 52毫秒( 94.00% ) 13.6 MB( 45.02% ) 中等的 36毫秒( 95.77% ) 13.7 MB( 73.48% ) 中等的 68毫秒( 88.56% ) ...
克拉兹问题(Kratzy Problem)是一个在计算机科学和算法理论中被广泛研究的问题,它的核心是寻找最小的非负整数解,使得一系列线性同余方程组成立。这个问题在密码学、编码理论以及计算复杂性理论等领域有重要应用。...
2.2 Minimal Hardware Programming: Pseudocodes 43 2.3 The IBM 704 and Fortran 45 2.4 Functional Programming: LISP 52 2.5 The First Step Toward Sophistication: ALGOL 60 57 2.6 Computerizing ...
43 3.6.7 Barrier objects . . . . . . . . . . . . . . . . . . . . . . . . 44 3.7 Queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 3.7.1 Queue hint . . . . . . . . . . . . . ....
第43章 第46章 47-置换-ii.md 第48章 第49章 5个最长回文子串.md 50-powx-n.md 6字形转换.md 7-反向整数.md 9回文数101-150(数量:30) 第101章 第102章 103二叉树之字形水平遍历.md 二叉树最大深度104.md 105...
这篇内容主要围绕的是冀教版九年级英语全册Unit8《Culture Shapes Us》Lesson43《A Visit to Chinatown》的课程,其中涉及到的知识点主要包括词汇学习、句子翻译以及课文阅读理解。 一、词汇学习 1. underground: ...
《MATLAB神经网络43个案例分析:连续Hopfield神经网络在旅行商问题优化计算中的应用》 在MATLAB环境中,神经网络作为一种强大的工具,被广泛应用于解决各种复杂问题,其中包括优化问题。本资料集中,我们将深入探讨...
The fusion between graph theory and combinatorial optimization has led to theoretically profound and ...CHAPTER 43 - Rectilinear Steiner Minimum Trees CHAPTER 44 - Parameter Algorithms and Complexity
在这个主题中,我们关注的是连续Hopfield神经网络以及它在旅行商问题(Traveling Salesman Problem, TSP)优化计算中的应用。 Hopfield网络是一种具有联想记忆功能的模型,由John J. Hopfield在1982年提出,它主要由...
lrzsz-0.12.20-43.el8.x86_64.rpm libnsl-2.28-164.el8.i686.rpm libnsl-2.28-164.el8.x86_64.rpm yum-utils-4.0.21-3.el8.noarch.rpm vim-minimal-8.0.1763-16.el8.x86_64.rpm python3-dnf-4.7.0-4.el8.noarch.rpm ...
pgdg-redhat-repo-latest.noarch.rpm