
数字计算技巧
文章平均质量分 69
northwolves
MS-VB-MVP
MS-EXCEL-MVP
展开
-
VBA实现任意n阶幻方的一种填法(n≥3)
参考http://blog.youkuaiyun.com/northwolves/archive/2007/09/23/1796696.aspx的思路,拟代码如下:Sub magicsquare(ByVal n As Long, ByRef matrix())Dim i As Long, j As Long, k As Long, p As Long, a(), b()ReDim matrix(1 To原创 2007-09-23 21:56:00 · 2119 阅读 · 0 评论 -
Largest Ten Digit Powers
The idea was Inspirated from the following link: Homogeneous Square Numbers (Provided by mathe, http://bbs.emath.ac.cn/thread-78-1-1.html) Look at the 10-digit number 9876543210,its the large原创 2009-01-11 15:39:00 · 2005 阅读 · 0 评论 -
nth prime number contain n as their substring within 100000000
A small VBA code to get these numbers: Sub Main() Dim i&, j&, k&, n&, num&, a(100000000) As Byte, p(1 To 10000000) As Long num = 1 p(num) = 2 The 1st prime n = 10原创 2009-01-11 21:27:00 · 1016 阅读 · 0 评论 -
前n个自然数的阶乘之和(单数,双数,全部)
电脑上翻出老代码,好几年前写的,尽管效率比较低,也可一用.Sub calc(ByVal n As Long, Optional types As String = "全部", Optional ByRef factorial As String, Optional ByRef sumfactorial As String)Dim numlen As Long, last As Lo原创 2008-11-21 20:08:00 · 2336 阅读 · 0 评论 -
Ten Digit Powers
With helps of many friends, the Ten Digit Powers sequence has been updated to n=128. More details,see Ten digit numbers Millions thanks to 无心人,mathe and gxqcn. The sequence was showed as原创 2009-01-13 21:45:00 · 1062 阅读 · 0 评论 -
分解质因数一例
100!+1=93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000001=101*14303*149239*35043原创 2008-11-23 15:01:00 · 1058 阅读 · 2 评论 -
Multi select elements which sums upto a certain number from an array
Give an array and a certain number,how to select some of the elements to sums upto the number?The following codes can bring you one or more solutions out:Sub Solve(ByVal Total As Double, B原创 2008-11-25 19:37:00 · 1808 阅读 · 0 评论 -
Which Numbers are the Sum of Two Squares?
The main goal of todays lecture is to prove the following theorem. Theorem 1.1 A number is a sum of two squares if and only if all prime factors of of the form have even exponent in the prim转载 2008-11-24 19:50:00 · 1197 阅读 · 0 评论 -
The four number game
The Four Numbers Game is a mathematical game, as taught by Dr. Paul Sally, Prof. of Mathematics at the University of Chicago. To play this game, draw a square and put a number at each corner, thus: 5_原创 2008-11-24 20:27:00 · 852 阅读 · 0 评论 -
一道趣味算术题
题目地址:http://club.excelhome.net/thread-175411-1-1.html 先看几个数:312132,231213,41312432,23421314 可以看到以上字串有以下特点: 2个1 之间有1个数,2个2 之间有2个数,2个3之间有3个数... 试找出由(1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,原创 2008-11-26 10:31:00 · 31964 阅读 · 41 评论 -
一个九位数由1-9数字组成并前N 位被N整除
题目:请将123456789九个数字以特定的顺序排列,组成一个9位数ABCDEFGHI(每个数字只能使用一次),使得:1.第一位数字组成的整数可以被1整除2.第一、二位数字组成的整数可以被2整除3.第一、二、三位数字组成的整数可以被3整除4.第一、二、三、四位数字组成的整数可以被4整除......9.第一、二、三...九位数字组成的整数可以被9整除 分析:通常想法是遍历9!=原创 2008-11-26 19:13:00 · 8686 阅读 · 1 评论 -
Smallest Ten Digit Powers
This is a companion piece of Largest Ten Digit Powers . The codes are almostly same,with a few changes only. Function befit(ByVal s As String, ByVal num As Long) As Boolean tell if a string原创 2009-01-11 22:41:00 · 1298 阅读 · 0 评论 -
The Number of Triangles Formed by Intersecting Diagonals of a Regular Polygon
Reproduced from http://www.cs.uwaterloo.ca/journals/JIS/sommars/newtriangle.html Journal of Integer Sequences, Vol. 1 (1998), Article 98.1.5The Number of Triangles Fo转载 2009-01-09 19:02:00 · 9384 阅读 · 0 评论 -
用VBA来解决大数据量计算逆矩阵的问题
EXCEL2003中应用minverse求逆矩阵,该函数在excel中的确存在计算范围上的限制,可能最大的计算范围是52*52。下面给出一个VBA的解法Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Lo原创 2007-09-21 13:54:00 · 5237 阅读 · 1 评论 -
关于括号式子的计数
优快云优快云社区专题开发/技术/项目数据结构与算法超超版主的问题:如果有n对括号,组成一个式子,而且括号的最深嵌套层次为k 满足这个条件的式子一共有几种? 如果n=3,k=2则有3种: (())() ()(()) (()()) 能否找到递推公式? --------------------------------------------------------------原创 2007-09-30 22:02:00 · 1266 阅读 · 0 评论 -
四阶素数幻方问题
用1到16构成一个四阶幻方,要求任意相邻两个方格中的数字之各均为素数? (原帖见:http://topic.youkuaiyun.com/u/20070830/18/1f1957c1-5e66-4c3b-8883-d7eef64c8da1.html)NowCan 网友的解法:直接递归搜,4阶很快的。以下这个程序就是这样的思路,结果未经过验证。 /* 将1-N^2这N^2个数添如N*N的方格中,每个原创 2007-10-01 17:02:00 · 2674 阅读 · 0 评论 -
Do you know how many combinations to select n numbers from 1 to m with sum of which is mysum?
Do you know how many combinations to select n numbers from 1 to m with sum of which is sum?Sub getit()Dim m&, n&, mysum&, i&, j&, k&, count()m = 100: n = 30: mysum = 700ReDim count(m, n, -mysum T原创 2007-12-03 00:37:00 · 1694 阅读 · 0 评论 -
递归列举从数组b()中选出某些元素(允许重复)使其和等于num的所有组合
Dim mycount As Long, s(1 To 65536, 1 To 1), num As LongSub main()Dim a, bnum = 45b = Array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)ReDim a(num)a(0) = b(0)search num, 0, 0, a, b[a1].Resize(65原创 2008-10-24 19:37:00 · 1301 阅读 · 0 评论 -
Every positive integer is a sum of four integer squares
From(http://www.alpertron.com.ar/4SQUARES.HTM)Every positive integer is a sum of four integer squaresby Michael Barr IntroductionThe theorem of the title has been known for centuries, perh转载 2008-11-01 23:47:00 · 2509 阅读 · 0 评论 -
Lagrange's four-square theorem
Lagranges four-square theorem(http://en.wikipedia.org/wiki/Lagrange%27s_four-square_theorem)Lagranges four-square theorem, also known as Bachets conjecture, was proven in 1770 by Joseph Louis转载 2008-11-01 22:56:00 · 1495 阅读 · 0 评论 -
About Google Treasure Hunt 2008
今天比较高兴,一口气做完了四道题目。看来VB6 仍有用武之地,尽管速度着实令人失望。 Thank you for entering the Treasure Hunt! Here are the first correct entries we received for the email address northwolves@gmail.com: Questi原创 2008-12-30 15:37:00 · 994 阅读 · 0 评论 -
Google Treasure Hunt 2008--Robot Problem
QuestionA robot is located at the top-left corner of a 65 x 45 grid (marked Start in the diagram below).The robot can only move either down or right at any point in time. The robot is tryin原创 2009-01-01 12:46:00 · 1046 阅读 · 0 评论 -
Google Treasure Hunt 2008---Find the Smallest Prime Number
Question: Find the smallest number that can be expressed as the sum of 3 consecutive prime numbers, the sum of 11 consecutive prime numbers, the sum of 25 consecutive prime numbers, the sum of 171 con原创 2009-01-03 12:27:00 · 1065 阅读 · 0 评论 -
Multi select elements which sums upto a certain number from an array(II)
Give an array and a certain number,how to select some of the elements to sums upto the number? (Also see http://blog.youkuaiyun.com/northwolves/archive/2008/11/25/3372338.aspx)The following codes can brin原创 2009-02-03 20:49:00 · 1480 阅读 · 0 评论 -
My Sequences on The On-Line Encyclopedia of Integer Sequences
All the links: http://www.research.att.com/~njas/sequences/?q=northwolves&language=english A154532 a(n) = largest 10-digit number whose nth power contains each digit (0-9) n times原创 2009-02-03 21:00:00 · 988 阅读 · 0 评论 -
The Recent Ten Years
1+2-3-4^5+6*7*8*9=20001^2/3*4^5*6-7*8+9=20011-2+3-4^5+6*7*8*9=20021^2*3-4^5+6*7*8*9=20031^2+3-4^5+6*7*8*9=20041*2+3-4^5+6*7*8*9=20051+2+3-4^5+6*7*8*9=2006原创 2009-02-05 16:35:00 · 797 阅读 · 0 评论 -
一道趣味数学题(二)
123456789这九个按顺序排列的数,要求在它们之间插入若干个+,-,*,/ ,使其结果正好等于100如: 1*2*3*4+5+6+7*8+9=100 以下代码在http://blog.youkuaiyun.com/northwolves/archive/2004/07/25/51038.aspx基础上修改而成: Sub main() 开始计算getall 100getall 10原创 2009-11-20 13:23:00 · 9896 阅读 · 22 评论 -
Harmonic number sum
Problem1: Least k such that H(k) >= n, where H(k) is the harmonic number sum_{i=1..k} 1/i. Sub Harmonic_number_sum()Dim s As Double, i As Long, n As Longn = 1For i = 1 To 300000000s = s原创 2009-11-20 22:50:00 · 1413 阅读 · 0 评论 -
An inequality about sine function
A problem provided by me and solved by mathe in bbs.emath.ac.cn(See: http://zdu.spaces.live.com/blog/cns!C95152CB25EF2037!136.entry) In http://bbs.emath.ac.cn/viewthread.php?tid=49&page转载 2009-11-20 23:54:00 · 848 阅读 · 0 评论 -
一元多项式的幂
Function PowerPolynomial(ByVal f As String, ByVal n As Long) As String If n = 1 Then power = f: Exit Function Dim a() As Long, b, c(), s() As String, max As Long, i As Long, j As Long, k As原创 2010-01-17 14:23:00 · 1296 阅读 · 0 评论 -
Select n numbers from 1 to m with all of array 'all' and none of array 'none'
How to select n numbers from 1 to m with all of array all and none of array none? Try the following codes,please. Sub getall(ByVal m As Long, ByVal n As Long, ByRef all, ByRef none) Select原创 2009-12-15 22:07:00 · 1566 阅读 · 0 评论 -
整数三角形题目两则
问题1: 周长不大于n,边长为整数的三角形有多少个?解法: Function p(ByVal n As Long)周长n的三角形的个数If n Mod 2 Then n = n + 3p = Round(n ^ 2 / 48)End FunctionSub Main()Dim i As Long, cFor i = 1 To 10 ^ 6c = c +原创 2010-02-23 23:21:00 · 1718 阅读 · 0 评论 -
Continued Fraction of Squareroot
Continued Fraction can be find in http://mathworld.wolfram.com/ContinuedFraction.html Function ContinuedFraction(ByVal n As Long)Dim root As Long, p As Long, q As Long, b() As String, temp As Lo原创 2010-02-25 22:42:00 · 1409 阅读 · 1 评论 -
Fundamental Solution to Pell's Equation
From Wikipedia,Pells equationis any Diophantine equation of the formwhere n is a nonsquare integer and x and y are integers. We can calculate the x,y for certain n with the followi原创 2010-01-03 13:19:00 · 1794 阅读 · 1 评论 -
An UDF to calculate weekday
It seems feasible . Function myweekday(ByVal y As Long, ByVal m As Long, ByVal d As Long) As Long Dim bias As Long If m > 2 Then bias = m - 2 Else bias = 10 + m原创 2010-01-09 23:50:00 · 1266 阅读 · 0 评论 -
Get Integer sided triangles for which the area/perimeter ratio is integral
Problem: Consider the triangle with sides 6, 8 and 10. It can be seen that the perimeter and the area are both equal to 24. So the area/perimeter ratio is equal to 1. Consider also the原创 2010-05-04 23:19:00 · 1830 阅读 · 0 评论 -
Number of sets of natural numbers less than n which sum to n.
The integer sequence was in : A111133 Seems easy. Sub Calc() Dim n As Long, count(), i As Long n = 500 ReDim count(n) count(0) = 1 For i = 1 To n For j = n To原创 2010-01-17 17:07:00 · 1597 阅读 · 0 评论 -
Get prime numbers nearby a number less than 10^10
For any given number less than 10^10,you can get prime numbers from 10000 numbers nearby it by the following codes: Private Sub Command1_Click()Debug.Print primes10000(987654321)End Sub原创 2008-12-28 20:32:00 · 1160 阅读 · 0 评论 -
Nine-digit Fractions(II)
Problem: Suppose integer A,B(A>B) and single C were satisified A/B=C and all digits(1-9) each used just once in the both sides of the equality respectively. Try to get all solutions. Answer:原创 2009-02-11 01:16:00 · 1983 阅读 · 0 评论 -
猴子选大王的四种VB解法
题目:一堆猴子编号依次是1,2,3 ...n ,这群猴子(n个)按照1到n的顺序围坐一圈,从第1开始报数,报双数的猴子离开此圈,这样依次下来,直到圈中只剩下最后一只猴子,则该猴子为大王。 解法: 1.集合的方法(O(2N)): Function Monkeyking(ByVal n As Long) As LongDim all As New Collection,原创 2009-02-10 15:30:00 · 2371 阅读 · 5 评论