- 浏览: 138817 次
- 性别:
- 来自: 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 844问题描述: It can be seen that th ... -
Problem 51
2011-09-06 19:46 927问题描述: By replacing the ... -
Problem 50
2011-09-03 14:53 885问题描述: The prime 41, can b ... -
Problem 49
2011-08-28 15:34 887问题描述: The arithmetic seq ... -
Problem 47
2011-08-27 16:10 499问题描述: The first two co ... -
Problem 46
2011-08-26 18:08 554问题描述: It was proposed by Chr ... -
Problem 45
2011-08-25 18:24 910问题描述: Triangle, pentagona ... -
Problem 42
2011-08-23 09:18 809问题描述: The nth term of the se ... -
Problem 41
2011-08-19 15:08 675问题描述: We shall say that an n ... -
Problem 40
2011-08-18 14:27 749算法描述: An irrational decimal ... -
Problem 39
2011-08-17 15:28 829问题描述: If p is the perimeter ... -
Problem 38
2011-08-17 15:27 725问题描述: Take the number 192 an ... -
Problem 37
2011-08-17 15:26 713问题描述: The number 3797 has an ... -
Problem 36
2011-08-17 15:23 764问题描述: The decimal number, 58 ... -
Problem 35
2011-08-17 15:22 678问题描述: The number, 197, is ca ... -
Problem 34
2011-08-17 15:20 755问题描述: 145 is a curious numbe ... -
Problem 33
2011-08-17 15:18 727问题描述: The fraction 49/98 is ... -
Problem 32
2011-08-17 15:17 852问题描述: We shall say that an n ... -
Problem 30
2011-08-17 15:11 450问题描述: Surprisingly there ... -
Problem 29
2011-08-17 15:09 629问题描述: Consider all integer c ...
相关推荐
0-1-knapsack-problem-master (43).zip
Andrew Stankevich Contest 45 Problem analysis, cf
打地鼠游戏设计c
离线安装包,亲测可用
Problem B:Pebble Merging Description 在一个圆形操场的四周摆放着n 堆石子。现要将石子 有次序地合并成一堆。规定每次只能选相邻的2 堆石 子合并成新的一堆,并将新的一堆石子数记为该次合 并的得分。试设计一...
离线安装包,亲测可用
离线安装包,亲测可用
help you fix the D3dx9_43 missing problem
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% ) ...
2.11.2 Maximization Problem Treatment 43 2.11.3 Treatment of “Greater Than Type” Constraints 43 2.11.4 Discrete and Integer Design Variables 44 2.11.5 Feasible Set 45 2.11.6 Active/Inactive/Violated...
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 ...
LESSON 5 Solving Word Problems Using Percents 43 LESSON 6 Solving Word Problems Using Proportions 51 LESSON 7 Solving Word Problems Using Formulas 60 Quiz 2 66 REFRESHER IV Equations 69 LESSON 8 ...
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...
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
4.1 The maximum-subarray problem 68 4.2 Strassen's algorithm for matrix multiplication 75 4.3 The substitution method for solving recurrences 83 4.4 The recursion-tree method for solving recurrences ...
3 Growth of Functions 43 3.1 Asymptotic notation 43 3.2 Standard notations and common functions 53 4 Divide-and-Conquer 65 4.1 The maximum-subarray problem 68 4.2 Strassen’s algorithm for matrix ...
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 ...