home *** CD-ROM | disk | FTP | other *** search
/ ftp.pasteur.org/FAQ/ / ftp-pasteur-org-FAQ.zip / FAQ / puzzles / archive / arithmetic / part1 next >
Encoding:
Internet Message Format  |  1996-04-26  |  63.6 KB

  1. Received: from MIT.EDU ([18.69.0.28]) by bloom-picayune.MIT.EDU (8.6.13/2.3JIK) with SMTP id PAA05329; Sat, 20 Apr 1996 15:11:17 -0400
  2. Received: from [199.164.164.1] by MIT.EDU with SMTP
  3.     id AA15680; Sat, 20 Apr 96 14:11:19 EDT
  4. Received: by questrel.questrel.com (940816.SGI.8.6.9/940406.SGI)
  5.     for news-answers-request@mit.edu id LAA25213; Sat, 20 Apr 1996 11:12:14 -0700
  6. Newsgroups: rec.puzzles,news.answers,rec.answers
  7. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!spool.mu.edu!howland.reston.ans.net!europa.eng.gtefsd.com!uunet!questrel!chris
  8. From: chris@questrel.questrel.com (Chris Cole)
  9. Subject: rec.puzzles Archive (arithmetic), part 03 of 35
  10. Message-Id: <puzzles/archive/arithmetic/part1_745653851@questrel.com>
  11. Followup-To: rec.puzzles
  12. Summary: This is part of an archive of questions
  13.  and answers that may be of interest to
  14.  puzzle enthusiasts.
  15.  Part 1 contains the index to the archive.
  16.  Read the rec.puzzles FAQ for more information.
  17. Sender: chris@questrel.questrel.com (Chris Cole)
  18. Reply-To: archive-comment@questrel.questrel.com
  19. Organization: Questrel, Inc.
  20. References: <puzzles/archive/Instructions_745653851@questrel.com>
  21. Date: Wed, 18 Aug 1993 06:04:31 GMT
  22. Approved: news-answers-request@MIT.Edu
  23. Expires: Thu, 1 Sep 1994 06:04:11 GMT
  24. Lines: 1860
  25. Xref: senator-bedfellow.mit.edu rec.puzzles:24994 news.answers:11514 rec.answers:1914
  26. Apparently-To: news-answers-request@mit.edu
  27.  
  28. Archive-name: puzzles/archive/arithmetic/part1
  29. Last-modified: 17 Aug 1993
  30. Version: 4
  31.  
  32.  
  33. ==> arithmetic/7-11.p <==
  34. A customer at a 7-11 store selected four items to buy, and was told
  35. that the cost was $7.11.  He was curious that the cost was the same
  36. as the store name, so he inquired as to how the figure was derived.
  37. The clerk said that he had simply multiplied the prices of the four
  38. individual  items.  The customer  protested  that  the four  prices     
  39. should have been ADDED,  not MULTIPLIED.  The  clerk said that that
  40. was OK with him, but, the result was still the same: exactly $7.11.
  41.  
  42. What were the prices of the four items?
  43.  
  44. ==> arithmetic/7-11.s <==
  45. The prices are: $1.20, $1.25, $1.50, and $3.16
  46.  
  47. $7.11 is not the only number which works.  Here are the first 160 such
  48. numbers, preceded by a count of distinct solutions for that price.
  49. Note that $7.11 has a single, unique solution.
  50.  
  51.        1 -  $6.44      1 -  $7.83      2 -  $9.20      3 - $10.89 
  52.        1 -  $6.51      1 -  $7.86      1 -  $9.23      1 - $10.95 
  53.        1 -  $6.60      3 -  $7.92      1 -  $9.24      2 - $11.00 
  54.        1 -  $6.63      1 -  $8.00      1 -  $9.27      1 - $11.07 
  55.        1 -  $6.65      1 -  $8.01      2 -  $9.35      1 - $11.13 
  56.        1 -  $6.72      1 -  $8.03      3 -  $9.36      1 - $11.16 
  57.        2 -  $6.75      5 -  $8.10      1 -  $9.38      1 - $11.22 
  58.        1 -  $6.78      1 -  $8.12      5 -  $9.45      2 - $11.25 
  59.        1 -  $6.80      1 -  $8.16      2 -  $9.48      2 - $11.27 
  60.        2 -  $6.84      2 -  $8.19      1 -  $9.54      1 - $11.30 
  61.        1 -  $6.86      1 -  $8.22      1 -  $9.57      1 - $11.36 
  62.        1 -  $6.89      1 -  $8.25      1 -  $9.59      1 - $11.40 
  63.        2 -  $6.93      3 -  $8.28      2 -  $9.60      2 - $11.43 
  64.        1 -  $7.02      3 -  $8.33      1 -  $9.62      2 - $11.52 
  65.        1 -  $7.05      1 -  $8.36      2 -  $9.63      2 - $11.55 
  66.        2 -  $7.07      1 -  $8.37      1 -  $9.66      2 - $11.61 
  67.        1 -  $7.08      2 -  $8.40      1 -  $9.68      1 - $11.69 
  68.        1 -  $7.11      1 -  $8.45      2 -  $9.69      1 - $11.70 
  69.        1 -  $7.13      2 -  $8.46      1 -  $9.78      1 - $11.88 
  70.        2 -  $7.14      1 -  $8.52      2 -  $9.80      1 - $11.90 
  71.        3 -  $7.20      5 -  $8.55      1 -  $9.81      1 - $11.99 
  72.        1 -  $7.25      1 -  $8.60      1 -  $9.87      1 - $12.06 
  73.        1 -  $7.26      4 -  $8.64      4 -  $9.90      1 - $12.15 
  74.        2 -  $7.28      1 -  $8.67      1 -  $9.92      1 - $12.18 
  75.        1 -  $7.29      1 -  $8.69      2 -  $9.99      1 - $12.24 
  76.        3 -  $7.35      1 -  $8.73      1 - $10.01      1 - $12.30 
  77.        1 -  $7.37      2 -  $8.75      1 - $10.05      1 - $12.32 
  78.        1 -  $7.47      1 -  $8.76      2 - $10.08      1 - $12.35 
  79.        1 -  $7.50      1 -  $8.78      1 - $10.17      2 - $12.42 
  80.        1 -  $7.52      5 -  $8.82      1 - $10.20      1 - $12.51 
  81.        4 -  $7.56      1 -  $8.85      2 - $10.26      1 - $12.65 
  82.        1 -  $7.62      1 -  $8.88      3 - $10.29      2 - $12.69 
  83.        4 -  $7.65      2 -  $8.91      3 - $10.35      1 - $12.75 
  84.        1 -  $7.67      1 -  $8.94      2 - $10.44      1 - $12.92 
  85.        2 -  $7.70      1 -  $8.96      1 - $10.53      1 - $12.96 
  86.        3 -  $7.74      3 -  $9.00      1 - $10.56      1 - $13.23 
  87.        1 -  $7.77      1 -  $9.02      1 - $10.64      1 - $13.41 
  88.        1 -  $7.79      2 -  $9.03      2 - $10.71      1 - $13.56 
  89.        2 -  $7.80      1 -  $9.12      3 - $10.80      1 - $14.49 
  90.        1 -  $7.82      2 -  $9.18      1 - $10.85      1 - $15.18 
  91.  
  92.  
  93. There are plenty of solutions for five summands.  Here are a few:
  94.  
  95.          $8.28  -- at least two solutions
  96.          $8.47  -- at least two solutions
  97.          $8.82  -- at least two solutions
  98. --
  99.      Mark Johnson       mark@microunity.com       (408) 734-8100
  100.  
  101. There may be many approximate solutions, for example: $1.01, $1.15, $2.41,
  102. and $2.54.  These sum to $7.11 but the product is 7.1100061.
  103.  
  104. ==> arithmetic/arithmetic.progression.p <==
  105. Is there an arithmetic progression of 20 or more primes?
  106.  
  107. ==> arithmetic/arithmetic.progression.s <==
  108. There is an arithmetic progression of 21 primes:
  109.     142072321123 + 1419763024680 i, 0 <= i < 21.
  110.  
  111. It was discovered on 30 November 1990, by programs running in the background
  112. on a network of Sun 3 workstations in the Department of Computer Science,
  113. University of Queensland, Australia.
  114.  
  115. See: Andrew Moran and Paul Pritchard, The design of a background job
  116. on a local area network, Procs. 14th Australian Computer Science Conference,
  117. 1991, to appear.
  118.  
  119. ==> arithmetic/clock/day.of.week.p <==
  120. It's restful sitting in Tom's cosy den, talking quietly and sipping
  121. a glass of his Madeira.
  122.  
  123. I was there one Sunday and we had the usual business of his clock.
  124. When the radio gave the time at the hour, the Ormolu antique was 
  125. exactly 3 minutes slow.
  126.  
  127. "It loses 7 minutes every hour", my old friend told me, as he had done
  128. so many times before.  "No more and no less, but I've gotten used to
  129. it that way."
  130.  
  131. When I spent a second evening with him later that same month, I remarked
  132. on the fact that the clock was dead right by radio time at the hour.
  133. It was rather late in the evening, but Tom assured me that his treasure
  134. had not been adjusted nor fixed since my last visit.
  135.  
  136. What day of the week was the second visit?
  137.  
  138. From "Mathematical Diversions" by Hunter + Madachy
  139.  
  140. ==> arithmetic/clock/day.of.week.s <==
  141. The answer is 17 days and 3 hours later, which would have been a Wednesday.
  142. This is the only other time in the same month when the two would agree at all.
  143.  
  144. In 17 days the slow clock loses 17*24*7 minutes = 2856 minutes,
  145. or 47 hours and 36 minutes.  In 3 hours more it loses 21 minutes, so
  146. it has lost a total of 47 hours and 57 minutes.  Modulo 12 hours, it
  147. has *gained* 3 minutes so as to make up the 3 minutes it was slow on
  148. Sunday.  It is now (fortnight plus 3 days) exactly accurate.
  149.  
  150. Since the clock was not adjusted since the last visit, it's also
  151. possible that the radio time shifted by one hour due to a change to or
  152. from summer daylight saving time.  However, it turns out that the only
  153. additional possibilities that need to be considered are those of 4 days
  154. 15 hours later, when the clock would have lost 12 hours 57 minutes, and
  155. 29 days 15 hours later, when the clock would have lost 3 days 10 hours
  156. 57 minutes.  Without even considering the rules for when in the month the
  157. clock is changed, these possible solutions are ruled out because we know
  158. that both visits were in the evening ("I spent a second evening with him").
  159. and they involve times in a different part of the day.
  160.  
  161.  
  162. ==> arithmetic/clock/palindromic.p <==
  163. How many times per day does a digital clock display a palindromic number?
  164.  
  165.  
  166. ==> arithmetic/clock/palindromic.s <==
  167. The problem is underspecified.  Digital clocks may run from
  168.  
  169.     (a) 1:00 to 12:59
  170.     (b) 01:00 to 12:59
  171.     (c) 0:00 to 23:59
  172.     (d) 00:00 to 23:59
  173.     (e-h) any of the above with seconds appended, :00 to :59.
  174.  
  175. I agree that not all of these are common, but I have seen some uncommon
  176. ones.  For that matter, I've seen ones not on the above list -- the Toronto
  177. subway stations used to contain digital clocks that ran from 0:00 to 12:59
  178. (pm), then from 1:00 (pm) to 11:59 (pm), while a computer that I used to
  179. use had the inverse anomaly -- its time of day command displayed times
  180. from 12:00:00 to 12:59:59 (am), then 01:00:00 to 23:59:59!
  181.  
  182. I get the following results for the 8 cases.
  183.  
  184.     CASE    AM+PM    HOURS pals/hr  TOTAL    OVERALL TOTAL
  185.     (a)    yes    1-9     6     54
  186.             10-12     1      3    114
  187.   
  188.     (b)    yes    01-05     1      5
  189.             06-09     0      0
  190.             10-12     1      3    16
  191.  
  192.     (c)    no    0-9     6     60
  193.             10-15     1      6
  194.             16-19     0      0
  195.             20-23     1      4    70
  196.  
  197.     (d)    no    00-05     1      6
  198.             06-09     0      0
  199.             10-15     1      6
  200.             16-19     0      0
  201.             20-23     1      4    16
  202.  
  203.     (e)    yes    1-9    60    540
  204.             10-12     6     18    1116
  205.  
  206.     (f)    yes    01-05     6     30
  207.             06-09     0      0
  208.             10-12     6     18    96
  209.  
  210.     (g)    no    0-9    60    600
  211.             10-15     6     36
  212.             16-19     0      0
  213.             20-23     6     24    660
  214.  
  215.     (h)    no    00-05     6     36
  216.             06-09     0      0
  217.             10-15     6     36
  218.             16-19     0      0
  219.             20-23     6     24    96
  220.  
  221. --Mark Brader (msb@sq.com)
  222.  
  223. ==> arithmetic/clock/reversible.p <==
  224. How many times per day can the hour and minute hands on an analog clock switch
  225. roles and still signify a valid time, ignoring the second hand?
  226.  
  227. ==> arithmetic/clock/reversible.s <==
  228. Have 12 clocks C1, C2 ... C12 show 1:00, 2:00, ..., 12:00.  Have a
  229. clock C0 show 12:00
  230.  
  231. Now turn C0 around 12 hours, simultaneously turning C1-C12 so their
  232. hour hands always coincide with the minute hand of C0, i.e., as C0
  233. spans 12 hours, C1-C12 will span 1 hour, but for each possible placing
  234. of the hour hand, all 12 possible 'true' placings of the minute hand
  235. will be represented by one of the 12 clocks.
  236.  
  237. Each time the hour hand of C0 coincides with the minute hand of a
  238. C1-C12 clock we have a reversible valid time.  This happens regularly
  239. 12 times each C0 hour, but the first and last time is equal (12:00), so
  240. the number of reversible true times is 12*12-1 = 143 spaced regularly
  241. in the 12-hour interval, ie. each 5 min 2.0979+ sec
  242.  
  243. -- 
  244. stein.kulseth@tf.tele.no [X.400] stein.kulseth@nta.no [internet]
  245.  
  246. ==> arithmetic/clock/right.angle.p <==
  247. How many times per day do the hour and minute hands of a clock form a
  248. right angle?
  249.  
  250.  
  251. ==> arithmetic/clock/right.angle.s <==
  252. 44.  Twice each hour equals 48, less one between 2:00 and 4:00 and one between
  253. 8:00 and 10:00 for both A.M. and P.M.
  254.  
  255. ==> arithmetic/clock/thirds.p <==
  256. Do the 3 hands on a clock ever divide the face of the clock into 3
  257. equal segments, i.e. 120 degrees between each hand?       
  258.  
  259. ==> arithmetic/clock/thirds.s <==
  260. First let us assume that our clock has 60 divisions.  We will show that
  261. any time the hour hand and the minute hand are 20 divisions (120 degrees)
  262. apart, the second hand cannot be an integral number of divisions from the
  263. other hands, unless it is straight up (on the minute).
  264.  
  265. Let us use h for hours, m for minutes, and s for seconds.
  266. We will use =n to mean congruent mod n, thus 12 =5 7.
  267.  
  268. We know that m =60 12h, that is, the minute hand moves 12 times as fast
  269. as the hour hand, and wraps around at 60.
  270. We also have s =60 60m. This simplifies to s/60 =1 m, which goes to
  271. s/60 = frac(m) (assuming s is in the range 0 <= s < 60), which goes to
  272. s = 60 frac(m).  Thus, if m is 5.5, s is 30.
  273.  
  274. Now let us assume the minute hand is 20 divisions ahead of the hour hand.
  275. So m =60 h + 20, thus 12h =60 h + 20, 11h =60 20, and, finally,
  276. h =60/11 20/11 (read 'h is congruent mod 60/11 to 20/11').
  277. So all values of m are k + n/11 for some integral k and integral n,
  278. 0 <= n < 11.  s is therefore 60n/11.  If s is to be an integral number of
  279. units from m and h, we must have 60n =11 n.  But 60 and 11 are relatively
  280. prime, so this holds only for n = 0.  But if n = 0, m is integral, so
  281. s is 0.
  282.  
  283. Now assume, instead, that the minute hand is 20 divisions behind the hour hand.
  284. So m =60 h - 20, 12h =60 h - 20, 11h =60 -20, h =60/11 -20/11.
  285. So m is still k + n/11.  Thus s must be 0.
  286.  
  287. But if s is 0, h must be 20 or 40.  But this translates to 4 o'clock or
  288. 8 o'clock, at both of which the minute hand is at 0, along with the second
  289. hand.
  290.  
  291. Thus the 3 hands can never be 120 degrees apart, Q.E.D.
  292.  
  293. This assumes, of course, that the second hand is synchronized with the
  294. minute hand.  This is not true on some inexpensive analog watches.  This
  295. also assumes that the watch is not broken (:^)).
  296.  
  297. ==> arithmetic/consecutive.composites.p <==
  298. Are there 10,000 consecutive non-prime numbers?
  299.  
  300. ==> arithmetic/consecutive.composites.s <==
  301. 9973!+2 through 9973!+10006 are composite.
  302.  
  303. ==> arithmetic/consecutive.product.p <==
  304. Prove that the product of three or more consecutive positive integers cannot
  305. be a perfect square.
  306.  
  307. ==> arithmetic/consecutive.product.s <==
  308. Three consecutive numbers:
  309.   If a and b are relatively prime, and ab is a square,
  310.   then a and b are squares. (This is left as an exercise.)
  311.  
  312.   Suppose (n - 1)n(n + 1) = k^2, where n > 1.  
  313.   Then n(n^2 - 1) = k^2.  But n and (n^2 - 1) are relatively prime.
  314.   Therefore n^2 - 1 is a perfect square, which is a contradiction.
  315.  
  316. Four consecutive numbers:
  317.   n(n + 1)(n + 2)(n + 3) = (n^2 + 3n + 1)^2 - 1
  318.  
  319. Five consecutive numbers:
  320.   Assume the product is a integer square, call it m.
  321.  
  322.   The prime factorization of m must have even numbers of each prime factor.
  323.  
  324.   For each prime factor, p, of m, p >= 5, p^2k must divide one of the
  325. consecutive naturals in the product.  (Otherwise, the difference between two
  326. of the naturals in the product would be a positive multiple of a prime >= 5.
  327. But in this problem, the greatest difference is 4.) So we need only consider
  328. the primes 2 and 3.
  329.  
  330.   Each of the consecutive naturals is one of:
  331.     1)    a perfect square
  332.     2)    2 times a perfect square
  333.     3)    3 times a perfect square
  334.     4)    6 times a perfect square.
  335.  
  336.   By the shoe box principle, two of the five consecutive numbers must fall into
  337. the same category.
  338.  
  339.   If there are two perfect squares, then their difference being less than five
  340. limits their values to be 1 and 4.  (0 is not a natural number, so 0 and 1
  341. and 0 and 4 cannot be the perfect squares.)  But 1*2*3*4*5=120!=x*x where x
  342. is an integer.
  343.  
  344.   If there are two numbers that are 2 times a perfect square, then their
  345. difference being less than five implies that the perfect squares (which are
  346. multiplied by 2) are less than 3 apart, and no two natural squares differ by
  347. only 1 or 2.
  348.  
  349.   A similar argument holds for two numbers which are 3 times a perfect square.
  350.  
  351.   We cannot have the case that two of the 5 consecutive numbers are multiples
  352. (much less square multiples) of 6, since their difference would be >= 6, and
  353. our span of five consecutive numbers is only 4.
  354.  
  355.   Therefore the assumption that m is a perfect square does not hold.
  356.  
  357.   QED.
  358.  
  359. In general the equation:
  360.  
  361. y^2 = x(x+1)(x+2)...(x+n),    n > 3
  362.  
  363. has only the solution corresponding to y = 0.
  364.  
  365. This is a theorem of Rigge [O. Rigge, ``Uber ein diophantisches Problem'',
  366. IX Skan. Math. Kong. Helsingfors (1938)] and Erdos [P. Erdos, ``Note on
  367. products of consecutive integers,'' J. London Math. Soc. #14 (1939),
  368. pages 194-198].
  369.  
  370. A proof can be found on page 276 of [L. Mordell, ``Diophantine
  371. Equations'', Academic Press 1969].
  372.  
  373. ==> arithmetic/consecutive.sums.p <==
  374. Find all series of consecutive positive integers whose sum is exactly 10,000.
  375.  
  376. ==> arithmetic/consecutive.sums.s <==
  377. Generalize to find X (and I) such that
  378.     (X + X+1 + X+2 + ... + X+I) = T
  379. for any integer T.
  380.  
  381. You are asking for all (X,I) s.t. (2X+I)(I+1) = 2T.  The problem is
  382. (very) slightly easier if we don't restrict X to being positive, so
  383. we'll solve this first.
  384.  
  385. Note that 2X+I and I+1 must have different parities, so the answer
  386. to the relaxed question is N = 2*(o_1+1)*(o_2+1)*...*(o_n+1), where
  387. 2T = 2^o_0*3^o_1*...*p_n^o_n (the prime factorization); this is easily
  388. seen to be the number of ways we can break 2T up into two positive
  389. factors of differing parity (with order).
  390.  
  391. In particular, 20000 = 2^5*5^4, hence there are 2*(4+1) = 10 solutions
  392. for T = 10000.  These are (2X+I,I+1):
  393.  
  394. (32*1,5^4)   (32*5,5^3)   (32*5^2,5^2)   (32*5^3,5)   (32*5^4,1)
  395. (5^4,32*1)   (5^3,32*5)   (5^2,32*5^2)   (5,32*5^3)   (1,32*5^4)
  396.  
  397. And they give rise to the solutions (X,I):
  398.  
  399. (-296,624)   (28,124)   (388,24)   (1998,4)     (10000,0)
  400. (297,31)     (-27,179)  (-387,799) (-1997,3999) (-9999,19999)
  401.  
  402. If you require that X>0 note that this is true iff 2X+I > I+1 and
  403. hence the number of solutions to this problem is N/2 (due to the
  404. symmetry of the above ordered pairs).
  405.  
  406. ==> arithmetic/conway.p <==
  407. Describe the sequence a(1)=a(2)=1, a(n) = a(a(n-1)) + a(n-a(n-1)) for n>2.
  408.  
  409. ==> arithmetic/conway.s <==
  410. This sequence and its remarkable properties were discovered, apparently
  411. independently, by Douglas Hofstadter (circa 1975), John Conway (in the
  412. early 1980's), B.W. Connoly, and others. Since Conway discovered many of
  413. the deeper properties, and is the one responsible for popularizing the
  414. sequence, it seems appropriate to name the sequence after him.
  415.  
  416. Some properties of a(n):
  417.  
  418. --  a(n+1) - a(n) = 0 or 1
  419.  
  420. --  a(2^n) = 2^(n-1)
  421.  
  422. --  n/2 <= a(n) <= n
  423.  
  424. --  A(n)= 2a(n) - n    has zeros at the powers of 2 and 
  425.      positive "humps" in between
  426.  
  427. --  A(2^n + t) = A(2^(n+1) - t)  for t between 0 and 2^n,
  428.      i.e. the humps are symmetric
  429.  
  430. -- a(2n) <= 2a(n)
  431.  
  432. -- a(n)/n --> 1/2  as  n --> infinity
  433.  
  434. -- a(n) and A(n) are self-similar, in the sense that their values on the
  435.    (N+1)'st hump can be obtained by a "magnification" process applied
  436.    to the values on the N'th hump. They are *not* chaotic sequences,
  437.    since their asymptotics and combinatorial structure are very regular
  438.    and rigid.
  439.  
  440. In a lecture at Bell Labs in 1988, Conway asked for the rate at
  441. which  a(n)/n converges to 1/2.  In particular, he asked for
  442. N(epsilon), the last value of  n  such that  |a(n)/n - 1/2|
  443. exceeds epsilon, in the case  epsilon=1/20.  This problem was
  444. solved by Colin Mallows of Bell Labs: he found that  N(1/20)=1489
  445. and N(1/40)=6083008742. These values are reported in his article
  446. in the American Mathematical Monthly, January 1991, p. 5.
  447.  
  448. Conway's sequence has a deep combinatorial structure, and is intimately
  449. connected with all of the following: variants of Pascal's triangle, the
  450. Gaussian distribution, combinatorial operations on finite sets,
  451. coin-pushing games, and Fibonacci and Catalan numbers.  All of this is
  452. explained in my joint paper with Ravi Vakil; anyone who would like to
  453. receive a copy in LaTex format should contact me at the e-mail address
  454. listed below.
  455.  
  456. One byproduct of our work is an algorithm to determine  N(epsilon) for
  457. given positive epsilon.  Here are some particular values:
  458.  
  459.  e      Last  n  such that   |a(n)/n - 1/2| > e
  460. ----    ----------------------------------------------------------
  461. 1/20    1489  (found by Mallows in 1988)
  462. 1/30    758765
  463. 1/40    6083008742  (found by Mallows in 1988)
  464. 1/50    809308036481621
  465. 1/60    1684539346496977501739
  466. 1/70    55738373698123373661810220400
  467. 1/80    15088841875190938484828948428612052839
  468. 1/90    127565909103887972767169084026274554426122918035
  469. 1/100   8826608001127077619581589939550531021943059906967127007025
  470.  
  471. These values were computed by the Mathematica program listed below; the
  472. algorithm is explained in our paper.  To use the program, load it into
  473. Mathematica and type   neps[t]  for some numerical value of  t  (which
  474. should probably be smaller than 1/5 or so). The program will output  N(t),
  475. e.g.  neps[1/20] = 1489. These numbers grow very fast: N(epsilon) will be
  476. about 2^((0.138015/epsilon)^2), so  N(1/1000) will have about 5735 digits.
  477. The program requires very little memory space, but its runtime appears to
  478. grow rapidly as epsilon decreases (on a Sun 3, it took about one second to
  479. find the first value listed, and several minutes to find the last).
  480.  
  481. neps[eps_] := Block[{W}, L = 1 + Floor[(0.138015/eps)^2]; e = eps*2; 
  482.     W = processvector[L]; While[Length[W] > 0, 
  483.      nmax = 1 + Last[W][[4]]; L++; W = processvector[L]]; nmax]
  484.  
  485. processvector[L_] := 
  486.   Block[{V}, V = startvector[L]; While[notfound[V], V = newbody[V]]; V]
  487.  
  488. startvector[L_] := Select[initialvector[L], gt]
  489.  
  490. initialvector[L_] := 
  491.   Table[{L, b, Binomial[L - 1, b - 1], 
  492.     2^(L + 1) - Sum[Binomial[L, c], {c, b, L}]}, {b, 0, L - 1}]
  493.  
  494. c[0] = 0
  495.  
  496. c[n_] := c[n] = Sum[Binomial[2*a, a]/(a + 1), {a, 0, n - 1}]
  497.  
  498. gt[x_] := U[x] > e
  499.  
  500. U[x_] := (x[[3]] + M[x[[1]], x[[2]]])/(x[[4]] + incp[x[[1]], x[[2]]])
  501.  
  502. M[n_, n_] = -1
  503.  
  504. M[n_, k_] := Binomial[n - 1, K[n, k]] - Binomial[n - 1, k - 1] + c[K[n, k]]
  505.  
  506. K[n_, k_] := Min[k, n - k]
  507.  
  508. incp[n_, k_] := Max[M[n, k], 1]
  509.  
  510. notfound[V_] := 
  511.   Length[V] > 0 && Last[V][[2]] > 0 && Last[V][[1]] > Last[V][[2]]
  512.  
  513. newbody[V_] := Join[Drop[V, -1], newtail[V]]
  514.  
  515. newtail[V_] := Select[{vleft[Last[V]], vright[Last[V]]}, gt]
  516.  
  517. vleft[x_] := {x[[1]] - 1, x[[2]] - 1, x[[3]], x[[4]]}
  518.  
  519. vright[x_] := {x[[1]] - 1, x[[2]], x[[3]] + S[x[[1]] - 1, x[[2]] - 1], 
  520.    x[[4]] + Binomial[x[[1]] - 1, x[[2]] - 1]}
  521.  
  522. S[n_, k_] := Binomial[n - 1, k] - Binomial[n - 1, k - 1]
  523.  
  524.  
  525. -Tal Kubo     kubo@math.harvard.edu  or   kubo@zariski.harvard.edu
  526.  
  527. ==> arithmetic/digits/6.and.7.p <==
  528. Does every number which is not divisible by 5 have a multiple whose
  529. only digits are 6 and 7?
  530.  
  531. ==> arithmetic/digits/6.and.7.s <==
  532. Yes.  My proof follows:
  533.  
  534. Claim 1: For every k, there is a k-digit number whose only digits
  535. are 6 and 7, which is divisible by 2^k.
  536.  
  537. The proof is by induction.  Suppose N is a k-digit number 
  538. satisfying the above condition.  Then either N = 0 (mod 2^(k+1))
  539. or N = 2^k (mod 2^(k+1)). Note that 6(10^k) = 0 (mod 2^(k+1)),
  540. and 7(10^k) = 2^k (mod 2^(k+1)).  So, either 6*10^k + N or
  541. 7*10^k + N is divisible by 2^(k+1).
  542.  
  543. Claim 2:  If m and 10 are relatively prime, then for any r,
  544. there is a number N whose only digits are 6 and 7 such that
  545. N = r (mod m). 
  546.  
  547. Proof:  Let K be the (m^2)-digit number whose only digit is 6.
  548. There is an s, 0 <= s < m, so that K + s = r (mod m).
  549. Let N = K + 10^(m - 1) + 10^(2m - 2) + . . . + 10^(sm - s).
  550. Since 10^(im - i) = 1 (mod m), N = K + s (mod m) = r (mod m).
  551. Clearly, every digit of N is either 6 or 7. 
  552.  
  553. Claim 3: If n is not divisible by 5, then there is a number N whose
  554. only digits are 6 and 7, so that N is divisible by n. 
  555.  
  556. Proof:  We can write n = (2^k)m, with gcd(m,10)=1.
  557. Use claim 1 to find a k-digit number M, whose only digits are 6 and 7,
  558. which is divisible by 2^k.  Choose an integer r so that
  559. (10^k)r + M = 0 (mod m).  Use claim 2 to find a number K whose
  560. only digits are 6 and 7, so that K = r (mod m).  Let N = 10^k K + M.
  561. Then N = 0 (mod m) and N = 0 (mod 2^k), so N is divisible by n.
  562. Finally, the only digits of N are 6 and 7, so we are done.
  563.  
  564. --
  565. David Radcliffe                                radcliff@csd4.csd.uwm.edu
  566.  
  567. ==> arithmetic/digits/all.ones.p <==
  568. Prove that some multiple of any integer ending in 3 contains all 1s.
  569.  
  570. ==> arithmetic/digits/all.ones.s <==
  571. Let n be our integer; one such desired multiple is then
  572. (10^(phi(n))-1)/9.  All we need is that (n,10) = 1, and if the last
  573. digit is 3 this must be the case.  A different proof using the
  574. pigeonhole principle is to consider the sequence 1, 11, 111, ..., (10^n
  575. - 1)/9.  We must have at some point that either some member of our
  576. sequence = 0 (mod n) or else some value (mod n) is duplicated.  Assume
  577. the latter, with x_a and x_b, x_b>x_a,  possesing the duplicated
  578. remainders.  We then have that x_b - x-a = 0 (mod n).  Let m be the
  579. highest power of 10 dividing x_b - x_a.  Now since (10,n) = 1, we can
  580. divide by 10^m and get that (x_b - x_a)/10^m = 0 (n).  But (x_b -
  581. x_a)/10^m is a number containing only the digit 1.
  582.  
  583. Q.E.D.
  584.  
  585. ==> arithmetic/digits/arabian.p <==
  586. What is the Arabian Nights factorial, the number x such that x! has 1001
  587. digits?  How about the prime x such that x! has exactly 1001 zeroes on
  588. the tail end.  (Bonus question, what is the 'rightmost' non-zero digit in x!?)
  589.  
  590. ==> arithmetic/digits/arabian.s <==
  591. The first answer is 450!.
  592.  
  593. Determining the number of zeroes at the end of x! is relatively easy once
  594. you realize that each such zero comes from a factor of 10 in the product
  595.  
  596.    1 * 2 * 3 * ... * x
  597.  
  598. Each factor of 10, in turn, comes from a factor of 5 and a factor of 2.
  599. Since there are many more factors of 2 than factors of 5, the number of 5s
  600. determines the number of zeroes at the end of the factorial.
  601.  
  602. The number of 5s in the set of numbers 1 .. x (and therefore the number
  603. of zeroes at the end of x!) is:
  604.  
  605.   z(x) = int(x/5) + int(x/25) + int(x/125) + int(x/625) + ...
  606.  
  607. This series terminates when the powers of 5 exceed x.
  608.  
  609. I know of no simple way to invert the above formula (i.e., to find x for
  610. a given z(x)), but I can approximate it by noting that, except for the "int"
  611. function,
  612.  
  613.    5*z(x) - x = z(x)
  614.  
  615. which gives:
  616.  
  617.    x = 4*z(x) (approximately).
  618.  
  619. The given problem asked, "For what prime x is z(x)=1001".  By the above forumla,
  620. this is approximately 4*1001=4004.  However, 4004! has only
  621.  
  622.   800 + 160 + 32 + 6 + 1 = 999 zeroes at the end of it.
  623.  
  624. The numbers 4005! through 4009! all have 1000 zeroes at their end and
  625. the numbers 4010! through 4014! all have 1001 zeroes at their end.
  626.  
  627. Since the problem asked for a prime x, and 4011 = 3*7*191, the only solution
  628. is x=4013.
  629.  
  630. The problem of determining the rightmost nonzero digit in x! is somewhat more
  631. difficult.  If we took the numbers 1, 2, ... , x and removed all factors of 5
  632. (and an equal number of factors of 2), the remaining numbers multiplied
  633. together modulo 10 would be the answer.  Note that since there are still many
  634. factors of 2 left, the rightmost nonzero digit must be 2, 4, 6, or 8 (x > 1).
  635.  
  636. Letting r(x) be the rightmost nonzero digit in x!, an expression for r(x) is:
  637.  
  638.   r(x) = (r(int(x/5)) * w * r(x mod 10)) mod 10, x >= 10.
  639.  
  640. where w is 4 if int(x/10) is odd and 6 if it is even.
  641.  
  642. The values of r(x) for 0 <= x <= 9 are 1, 1, 2, 6, 4, 2, 2, 4, 2, and 8.
  643.  
  644. The way to see this is true is to take the numbers 1, 2, ..., x in groups
  645. of 10.  In each group, remove 2 factors of 10.  For example, from the
  646. set 1, 2, ..., 10, choose a factor of 2 from 2 and 6 and a factor of 5 from
  647. 5 and 10.  This leaves 1, 1, 3, 4, 1, 3, 7, 8, 9, 2.  Next, separate all the
  648. factors that came from multiples of 5.  The rightmost nonzero digit of x!
  649. can now (hopefully) be seen to be:
  650.  
  651.   r(x) = (r(int(x/5)) * w * r(x mod 10)) mod 10
  652.  
  653. where w is the rightmost digit in the number formed by multiplying the numbers
  654. 1, 2, 3, ..., 10*int(x/10) after the factors of 10 and the factors left over
  655. by the multiples of 5 have been removed.  In the example with x = 10, this
  656. would be (1 * 1 * 3 * 4 * 3 * 7 * 8 * 9) mod 10 = 4.  The "r(x mod 10)" term
  657. takes care of the numbers from 10*int(x/10)+1 up to x.
  658.  
  659. The "w" term can be seen to be 4 or 6 depending on whether int(x/10) is odd or
  660. even since, after removing 10*n+5 and 10*n+10 and a factor of 2 each from
  661. 10*n+2 and 10*n+6 from the group of numbers 10*n+1 through 10*n+10, the
  662. remaining factors (mod 10) always equals 4 and 4^t mod 10 = 4 if t is odd and
  663. 6 when t is even (t != 0).
  664.  
  665. So, finally, the rightmost nonzero digit in 4013! is found as follows:
  666.  
  667.   r(4013) = (r(802) * 4 * 6) mod 10
  668.   r(802)  = (r(160) * 6 * 2) mod 10
  669.   r(160)  = (r(32)  * 6 * 1) mod 10
  670.   r(32)   = (r(6)   * 4 * 2) mod 10
  671.  
  672. Using a table of r(x) for 0 <= x <= 9, r(6) = 2.  Then,
  673.  
  674.   r(32)   = (2 * 4 * 2) mod 10 = 6
  675.   r(160)  = (6 * 6 * 1) mod 10 = 6
  676.   r(802)  = (6 * 6 * 2) mod 10 = 2
  677.   r(4013) = (2 * 4 * 6) mod 10 = 8
  678.  
  679. Thus, the rightmost nonzero digit in 4013! is 8.
  680.  
  681. ==> arithmetic/digits/circular.p <==
  682. What 6 digit number, with 6 different digits, when multiplied by all integers
  683. up to 6, circulates its digits through all 6 possible positions, as follows:
  684. ABCDEF * 1 = ABCDEF
  685. ABCDEF * 3 = BCDEFA
  686. ABCDEF * 2 = CDEFAB
  687. ABCDEF * 6 = DEFABC
  688. ABCDEF * 4 = EFABCD
  689. ABCDEF * 5 = FABCDE
  690.  
  691. ==> arithmetic/digits/circular.s <==
  692. ABCDEF=142857 (the digits of the expansion of 1/7).
  693.  
  694. ==> arithmetic/digits/divisible.p <==
  695. Find the least number using 0-9 exactly once that is evenly divisible by each
  696. of these digits.
  697.  
  698. ==> arithmetic/digits/divisible.s <==
  699. Since the sum of the digits is 45, any permutation of the digits gives a
  700. multiple of 9.  To get a multiple of both 2 and 5, the last digit must
  701. be 0, and thus to get a multiple of 8 (and 4), the tens digit must be
  702. even, and the hundreds digit must be odd if the tens digit is 2 or 6,
  703. and even otherwise.  The number will also be divisible by 6, since it is
  704. divisible by 2 and 3, so 7 is all we need to check.  First, we will look
  705. for a number whose first five digits are 12345; now, 1234500000 has a
  706. remainder of 6 when divided by 7, so we have to arrange the remaining
  707. digits to get a remainder of 1.  The possible arrangements, in
  708. increasing order, are
  709.  
  710. 78960, remainder 0
  711. 79680, remainder 6
  712. 87960, remainder 5
  713. 89760, remainder 6
  714. 97680, remainder 2
  715. 98760, remainder 4
  716.  
  717. That didn't work, so try numbers starting with 12346; this is impossible
  718. because the tens digit must be 8, and the hundreds digit cannot be even.
  719. Now try 12347, and 1234700000 has remainder 2.  The last five digits can
  720. be
  721.  
  722. 58960, remainder 6
  723. 59680, remainder 5, so this works, and the number is
  724.  
  725. 1234759680.
  726.  
  727. ==> arithmetic/digits/equations/123456789.p <==
  728. In how many ways can "." be replaced with "+", "-", or "" (concatenate) in
  729. .1.2.3.4.5.6.7.8.9=1 to form a correct equation?
  730.  
  731. ==> arithmetic/digits/equations/123456789.s <==
  732.  1-2 3+4 5+6 7-8 9 = 1
  733. +1-2 3+4 5+6 7-8 9 = 1
  734.  1+2 3+4-5+6 7-8 9 = 1
  735. +1+2 3+4-5+6 7-8 9 = 1
  736. -1+2 3-4+5+6 7-8 9 = 1
  737.  1+2 3-4 5-6 7+8 9 = 1
  738. +1+2 3-4 5-6 7+8 9 = 1
  739.  1-2 3-4+5-6 7+8 9 = 1
  740. +1-2 3-4+5-6 7+8 9 = 1
  741.  1-2-3-4 5+6 7-8-9 = 1
  742. +1-2-3-4 5+6 7-8-9 = 1
  743.  1+2-3 4+5 6-7-8-9 = 1
  744. +1+2-3 4+5 6-7-8-9 = 1
  745. -1+2 3+4+5-6-7-8-9 = 1
  746. -1 2+3 4-5-6+7-8-9 = 1
  747.  1+2+3+4-5+6+7-8-9 = 1
  748. +1+2+3+4-5+6+7-8-9 = 1
  749. -1+2+3-4+5+6+7-8-9 = 1
  750.  1-2-3+4+5+6+7-8-9 = 1
  751. +1-2-3+4+5+6+7-8-9 = 1
  752.  1+2 3+4 5-6 7+8-9 = 1
  753. +1+2 3+4 5-6 7+8-9 = 1
  754.  1+2 3-4-5-6-7+8-9 = 1
  755. +1+2 3-4-5-6-7+8-9 = 1
  756.  1+2+3+4+5-6-7+8-9 = 1
  757. +1+2+3+4+5-6-7+8-9 = 1
  758. -1+2+3+4-5+6-7+8-9 = 1
  759.  1-2+3-4+5+6-7+8-9 = 1
  760. +1-2+3-4+5+6-7+8-9 = 1
  761. -1-2-3+4+5+6-7+8-9 = 1
  762.  1-2+3+4-5-6+7+8-9 = 1
  763. +1-2+3+4-5-6+7+8-9 = 1
  764.  1+2-3-4+5-6+7+8-9 = 1
  765. +1+2-3-4+5-6+7+8-9 = 1
  766. -1-2+3-4+5-6+7+8-9 = 1
  767. -1+2-3-4-5+6+7+8-9 = 1
  768. -1+2 3+4 5-6 7-8+9 = 1
  769.  1-2 3-4 5+6 7-8+9 = 1
  770. +1-2 3-4 5+6 7-8+9 = 1
  771. -1+2 3-4-5-6-7-8+9 = 1
  772. -1+2+3+4+5-6-7-8+9 = 1
  773.  1-2+3+4-5+6-7-8+9 = 1
  774. +1-2+3+4-5+6-7-8+9 = 1
  775.  1+2-3-4+5+6-7-8+9 = 1
  776. +1+2-3-4+5+6-7-8+9 = 1
  777. -1-2+3-4+5+6-7-8+9 = 1
  778.  1+2-3+4-5-6+7-8+9 = 1
  779. +1+2-3+4-5-6+7-8+9 = 1
  780. -1-2+3+4-5-6+7-8+9 = 1
  781. -1+2-3-4+5-6+7-8+9 = 1
  782.  1-2-3-4-5+6+7-8+9 = 1
  783. +1-2-3-4-5+6+7-8+9 = 1
  784.  1-2 3+4+5+6+7-8+9 = 1
  785. +1-2 3+4+5+6+7-8+9 = 1
  786.  1+2+3+4 5-6 7+8+9 = 1
  787. +1+2+3+4 5-6 7+8+9 = 1
  788.  1 2+3 4+5-6 7+8+9 = 1
  789. +1 2+3 4+5-6 7+8+9 = 1
  790.  1+2+3-4-5-6-7+8+9 = 1
  791. +1+2+3-4-5-6-7+8+9 = 1
  792. -1+2-3+4-5-6-7+8+9 = 1
  793.  1-2-3-4+5-6-7+8+9 = 1
  794. +1-2-3-4+5-6-7+8+9 = 1
  795. -1-2-3-4-5+6-7+8+9 = 1
  796. -1-2 3+4+5+6-7+8+9 = 1
  797.  1-2+3 4-5 6+7+8+9 = 1
  798. +1-2+3 4-5 6+7+8+9 = 1
  799.  1 2-3 4+5-6+7+8+9 = 1
  800. +1 2-3 4+5-6+7+8+9 = 1
  801. Total solutions  = 69 (26 of which have a leading "+", which is redundant)
  802.  
  803. 69/19683 = 0.35 %
  804.  
  805. for those who care (it's not very elegant but it did the trick):
  806.  
  807. #include <stdio.h>
  808. #include <math.h>
  809.  
  810. main (argc,argv)
  811.      int argc;
  812.      char *argv[];
  813. {
  814.   int sresult, result, operator[10],thisop;
  815.   char buf[256],ops[3];
  816.   int i,j,tot=0,temp;
  817.   
  818.   ops[0] = ' ';
  819.   ops[1] = '-';
  820.   ops[2] = '+';
  821.  
  822.   for (i=1; i<10; i++) operator[i] = 0;
  823.   
  824.   for (j=0; j < 19683; j++) {
  825.     result = 0;
  826.     sresult = 0;
  827.     thisop = 1;
  828.     for (i=1; i<10; i++) {
  829.       switch (operator[i]) {
  830.       case 0:
  831.     sresult = sresult * 10 + i;
  832.     break;
  833.       case 1:
  834.     result = result + sresult * thisop;
  835.     sresult = i;
  836.     thisop = -1;
  837.     break;
  838.       case 2:
  839.     result = result + sresult * thisop;
  840.     sresult = i;
  841.     thisop = 1;
  842.     break;
  843.       }
  844.     }
  845.   
  846.     result  = result + sresult * thisop;
  847.     if (result == 1) {
  848.       tot++;
  849.       for  (i=1;i<10;i++) 
  850.     printf("%c%d",ops[operator[i]],i);
  851.       printf(" = %d\n",result);
  852.     }
  853.     temp = 0;
  854.     operator[1] += 1;
  855.     for (i=1;i<10;i++) {
  856.       operator[i] += temp;
  857.       if (operator[i] > 2) { operator[i] = 0; temp = 1;}
  858.       else temp = 0;
  859.     }
  860.   
  861.   }
  862.   
  863.   printf("Total solutions  = %d\n" , tot);
  864. }
  865.  
  866. cwren@media.mit.edu (Christopher Wren)
  867.  
  868. ==> arithmetic/digits/equations/1992.p <==
  869. 1 = -1+9-9+2.  Extend this list to 2 through 100 on the left side of
  870. the equals sign.
  871.  
  872. ==> arithmetic/digits/equations/1992.s <==
  873. 1 = -1+9-9+2
  874. 2 = 1*9-9+2
  875. 3 = 1+9-9+2
  876. 4 = 1+9/9+2
  877. 5 = 1+9-sqrt(9)-2
  878. 6 = 1^9+sqrt(9)+2
  879. 7 = -1+sqrt(9)+sqrt(9)+2
  880. 8 = 19-9-2
  881. 9 = (1/9)*9^2
  882. 10= 1+(9+9)/2
  883. 11= 1+9+sqrt(9)-2
  884. 12= 19-9+2
  885. 13= (1+sqrt(9))!-9-2
  886. 14= 1+9+sqrt(9)!-2
  887. 15= -1+9+9-2
  888. 16= -1+9+sqrt(9)!+2
  889. 17= 1+9+9-2
  890. 18= 1+9+sqrt(9)!+2
  891. 19= -1+9+9+2
  892. 20= (19-9)*2
  893. 21= 1+9+9+2
  894. 22= (-1+sqrt(9))*(9-2)
  895. 23= (1+sqrt(9))!-sqrt(9)+2
  896. 24= -1+9*sqrt(9)-2
  897. 25= 1*9*sqrt(9)-2
  898. 26= 19+9-2
  899. 27= 1*9+9*2
  900. 28= 1+9+9*2
  901. 29= 1*9*sqrt(9)+2
  902. 30= 19+9+2
  903. 31= (1+sqrt(9))!+9-2
  904. 32= -1+sqrt(9)*(9+2)
  905. 33= 1*sqrt(9)*(9+2)
  906. 34= (-1+9+9)*2
  907. 35= -1+(9+9)*2
  908. 36= 1^9*sqrt(9)!^2
  909. 37= 19+9*2
  910. 38= 1*sqrt(9)!*sqrt(9)!+2
  911. 39= 1+sqrt(9)!*sqrt(9)!+2
  912. 40= (1+sqrt(9)!)*sqrt(9)!-2
  913. 41= -1+sqrt(9)!*(9-2)
  914. 42= (1+sqrt(9))!+9*2
  915. 43= 1+sqrt(9)!*(9-2)
  916. 44= -1+9*(sqrt(9)+2)
  917. 45= 1*9*(sqrt(9)+2)
  918. 46= 1+9*(sqrt(9)+2)
  919. 47= (-1+sqrt(9)!)*9+2
  920. 48= 1*sqrt(9)!*(sqrt(9)!+2)
  921. 49= (1+sqrt(9)!)*(9-2)
  922. 50= (-1+9)*sqrt(9)!+2
  923. 51= -1+9*sqrt(9)!-2
  924. 52= 1*9*sqrt(9)!-2
  925. 53= -1+9*sqrt(9)*2
  926. 54= 1*9*sqrt(9)*2
  927. 55= 1+9*sqrt(9)*2
  928. 56= 1*9*sqrt(9)!+2
  929. 57= 1+9*sqrt(9)!+2
  930. 58= (1+9)*sqrt(9)!-2
  931. 59= 19*sqrt(9)+2
  932. 60= (1+9)*sqrt(9)*2
  933. 61= (1+sqrt(9)!)*9-2
  934. 62= -1+9*(9-2)
  935. 63= 1*9*(9-2)
  936. 64= 1+9*(9-2)
  937. 65= (1+sqrt(9)!)*9+2
  938. 66= 1*sqrt(9)!*(9+2)
  939. 67= 1+sqrt(9)!*(9+2)
  940. 68= -(1+sqrt(9))!+92
  941. 69= (1+sqrt(9))!+(9/.2)
  942. 70= (1+9)*(9-2)
  943. 71= -1-9+9^2
  944. 72= (1+sqrt(9))*9*2
  945. 73= -19+92
  946. 74= (-1+9)*9+2
  947. 75= -1*sqrt(9)!+9^2
  948. 76= 1-sqrt(9)!+9^2
  949. 77= (1+sqrt(9)!)*(9+2)
  950. 78= -1+9*9-2
  951. 79= 1*9*9-2
  952. 80= 1+9*9-2
  953. 81= 1*9*sqrt(9)^2
  954. 82= -1+9*9+2
  955. 83= 1*9*9+2
  956. 84= 1+9*9+2
  957. 85= -1-sqrt(9)!+92
  958. 86= -1*sqrt(9)!+92
  959. 87= 1-sqrt(9)!+92
  960. 88= (1+9)*9-2
  961. 89= -1*sqrt(9)+92
  962. 90= 1-sqrt(9)+92
  963. 91= -1^9+92
  964. 92= (1+9)*9+2
  965. 93= 1^9+92
  966. 94= -1+sqrt(9)+92
  967. 95= 19*(sqrt(9)+2)
  968. 96= -1+99-2
  969. 97= 1*99-2
  970. 98= 1+99-2
  971. 99= 1*9*(9+2)
  972. 100= -1+99+2
  973.  
  974. ==> arithmetic/digits/equations/24.p <==
  975. Form an expression that evaluates to 24 that contains two 3's, two 7's,
  976. and zero or more of the operators +, -, *, and /, and parentheses.  What
  977. about two 4's and two 7's, or three 5's and one 1, or two 3's and two 8's?
  978.  
  979. ==> arithmetic/digits/equations/24.s <==
  980. 7*(3+3/7)
  981. 7*(4-4/7)
  982. 5*(5-1/5)
  983. 8/(3-8/3)
  984.  
  985. ==> arithmetic/digits/equations/383.p <==
  986. Make 383 out of 1,2,25,50,75,100 using +,-,*,/.
  987.  
  988. ==> arithmetic/digits/equations/383.s <==
  989. You can get 383 with ((2+50)/25+1)*100+75.
  990.  
  991. Of course, if you expect / as in C, the above expression is just 375.
  992. But then you can get 383 with (25*50-100)/(1+2).  Pity there's no way
  993. to use the 75.
  994.  
  995. If we had a language that rounded instead of truncating, we could use
  996. ((1+75+100)*50)/(25-2) or (2*75*(25+100))/(50-1).
  997.  
  998. I imagine your problem lies in not dividing things that aren't
  999. divisible.
  1000.  
  1001. Dan Hoey
  1002. Hoey@AIC.NRL.Navy.Mil
  1003.  
  1004. ==> arithmetic/digits/equations/find.p <==
  1005. Write a program for finding expressions built out of given numbers and using
  1006. given operators that evaluate to a given value, or listing all possible values.
  1007.  
  1008. ==> arithmetic/digits/equations/find.s <==
  1009. As set up, it requires recompilation for different sets of numbers;
  1010. it's currently set up for 8,8,3,3; to try in other numbers, stick 'em
  1011. in the 'val' array.  To find all target numbers for which the equation
  1012. is valid, uncomment the 't' loop and 'target = t', and extend the range
  1013. to be checked... you might want to turn off VERBOSE.  I don't bother
  1014. with eliminating symmetries if equal vals are given (like 8 8 3 3), so
  1015. I normally use it like
  1016.  
  1017.     numop 24 | sort | uniq
  1018.  
  1019. As it stands, this gives the output:
  1020.  
  1021. 8 / (3 - (8 / 3)) = 24.0
  1022. 8 / (3 - (8 / 3)) = 24.0
  1023. 8 / (3 - (8 / 3)) = 24.0
  1024. 8 / (3 - (8 / 3)) = 24.0
  1025.  
  1026. As you can see, there are five different kinds of binary trees with
  1027. exactly four leaf nodes.  The program tries all four operators in each
  1028. place, and all four values in each of the leaves, guaranteeing that each
  1029. is used only once... a fairly quick operation.  A small extract from
  1030. 'numop 1' shows the five different shapes of trees:
  1031.  
  1032. ((3 * 8) / 3) / 8 = 1.0
  1033. (3 * (8 / 3)) / 8 = 1.0
  1034. (3 - 3) + (8 / 8) = 1.0
  1035. 3 * ((8 / 3) / 8) = 1.0
  1036. 3 * (8 / (3 * 8)) = 1.0
  1037.  
  1038. Probably FUDGE ought to be set a little lower, for more confidence that
  1039. the equality isn't fortuitous.  Extensions to other binary operators are
  1040. obvious; unary operators and more values are not.  For a more general
  1041. problem I'd go recursive, use exact rational arithmetic, and have a fine
  1042. old time.
  1043.  
  1044. Enjoy...
  1045.  
  1046.     Jim Gillogly <uunet!rand.org!James_Gillogly>
  1047.     21 Wedmath S.R. 1993, 10:58
  1048. ----------------------------------------------------------------
  1049.  
  1050. /* numop: using elementary operations on 4 numbers, find a
  1051.  * desired result; e.g. 24.
  1052.  *
  1053.  * Don't worry about symmetries resulting in multiple correct answers.
  1054.  *
  1055.  * 11 Aug 93, SCRYER
  1056.  */
  1057.  
  1058. #include <stdio.h>
  1059.  
  1060. #define VERBOSE
  1061.  
  1062.  
  1063. #define MUL 0
  1064. #define DIV 1
  1065. #define ADD 2
  1066. #define SUB 3
  1067.  
  1068. #define FUDGE 0.01
  1069.  
  1070. float val[4] = {8, 8, 3, 3};
  1071. float eval(), atof(), fabs();
  1072. char nameop();
  1073.  
  1074. int divzero;
  1075.  
  1076. main(argc, argv)
  1077. int argc;
  1078. char *argv[];
  1079. {
  1080.     int op1, op2, op3;
  1081.     int iv1, iv2, iv3, iv4;
  1082.     int used[4];
  1083.     int i;
  1084.     float target;
  1085.     float e1, e2, e3;
  1086.     int t, winner;
  1087.  
  1088.     if (argc != 2)
  1089.     {
  1090.     fprintf(stderr, "Usage: numop <target>\n");
  1091.     exit(1);
  1092.     }
  1093.     target = atof(argv[1]);
  1094.  
  1095.  
  1096. /* for (t = -1000; t < 1000; t++) */
  1097.  {
  1098. /*    target = t;*/
  1099.     winner = 0;
  1100.  
  1101.     for (i = 0; i < 4; i++) used[i] = 0;
  1102.  
  1103.     for (op1 = 0; op1 < 4; op1++)
  1104.     for (op2 = 0; op2 < 4; op2++)
  1105.         for (op3 = 0; op3 < 4; op3++)
  1106.         for (iv1 = 0; iv1 < 4; iv1++)
  1107.         {
  1108.             used[iv1] = 1;
  1109.             for (iv2 = 0; iv2 < 4; iv2++)
  1110.             {
  1111.             if (used[iv2]) continue;
  1112.             used[iv2] = 1;
  1113.             for (iv3 = 0; iv3 < 4; iv3++)
  1114.             {
  1115.                 if (used[iv3]) continue;
  1116.                 used[iv3] = 1;
  1117.                 for (iv4 = 0; iv4 < 4; iv4++)
  1118.                 {
  1119.                 if (used[iv4]) continue;
  1120.  
  1121.                 /* Case 1 */
  1122.                 divzero = 0;
  1123.                 e3 = eval(op3, val[iv3], val[iv4]);
  1124.                 e2 = eval(op2, val[iv1], val[iv2]);
  1125.                 e1 = eval(op1, e2, e3);                         /* (u + v) * (w - x) */
  1126.                 if (fabs(e1 - target) < FUDGE && ! divzero)
  1127. #ifdef VERBOSE
  1128.                     printf("(%.0f %c %.0f) %c (%.0f %c %.0f) = %.1f\n",
  1129.                     val[iv1], nameop(op2), val[iv2], nameop(op1),
  1130.                     val[iv3], nameop(op3), val[iv4], e1);
  1131. #else
  1132.                     winner = 1;
  1133. #endif
  1134.                 /* Case 2 */
  1135.                 divzero = 0;
  1136.                 e3 = eval(op3, val[iv1], val[iv2]);
  1137.                 e2 = eval(op2, e3, val[iv3]);
  1138.                 e1 = eval(op1, e2, val[iv4]);                   /* ((u + v) * w) - x */
  1139.                 if (fabs(e1 - target) < FUDGE && ! divzero)
  1140. #ifdef VERBOSE
  1141.                     printf("((%.0f %c %.0f) %c %.0f) %c %.0f = %.1f\n",
  1142.                     val[iv1], nameop(op3), val[iv2], nameop(op2), val[iv3], nameop(op1), val[iv4], e1);
  1143. #else
  1144.                     winner = 1;
  1145. #endif
  1146.  
  1147.                 /* Case 3 */
  1148.                 divzero = 0;
  1149.                 e3 = eval(op3, val[iv2], val[iv3]);
  1150.                 e2 = eval(op2, val[iv1], e3);
  1151.                 e1 = eval(op1, e2, val[iv4]);                   /* (u + (v * w)) - x */
  1152.                 if (fabs(e1 - target) < FUDGE && ! divzero)
  1153. #ifdef VERBOSE
  1154.                     printf("(%.0f %c (%.0f %c %.0f)) %c %.0f = %.1f\n",
  1155.                     val[iv1], nameop(op2), val[iv2], nameop(op3), val[iv3],
  1156.                     nameop(op1), val[iv4], e1);
  1157. #else
  1158.                     winner = 1;
  1159. #endif
  1160.  
  1161.                 /* Case 4 */
  1162.                 divzero = 0;
  1163.                 e3 = eval(op3, val[iv2], val[iv3]);
  1164.                 e2 = eval(op2, e3, val[iv4]);
  1165.                 e1 = eval(op1, val[iv1], e2);                   /* u + ((v * w) - x) */
  1166.                 if (fabs(e1 - target) < FUDGE && ! divzero)
  1167. #ifdef VERBOSE
  1168.                     printf("%.0f %c ((%.0f %c %.0f) %c %.0f) = %.1f\n",
  1169.                     val[iv1], nameop(op1), val[iv2], nameop(op3), val[iv3],
  1170.                     nameop(op2), val[iv4], e1);
  1171. #else
  1172.                     winner = 1;
  1173. #endif
  1174.  
  1175.                 /* Case 5 */                                    /* u + (v * (w - x)) */
  1176.                 divzero = 0;
  1177.                 e3 = eval(op3, val[iv3], val[iv4]);
  1178.                 e2 = eval(op2, val[iv2], e3);
  1179.                 e1 = eval(op1, val[iv1], e2);
  1180.                 if (fabs(e1 - target) < FUDGE && ! divzero)
  1181. #ifdef VERBOSE
  1182.                     printf("%.0f %c (%.0f %c (%.0f %c %.0f)) = %.1f\n",
  1183.                     val[iv1], nameop(op1), val[iv2], nameop(op2), val[iv3],
  1184.                     nameop(op3), val[iv4], e1);
  1185. #else
  1186.                     winner = 1;
  1187. #endif
  1188.  
  1189.                 }
  1190.                 used[iv3] = 0;
  1191.             }
  1192.             used[iv2] = 0;
  1193.             }
  1194.             used[iv1] = 0;
  1195.         }
  1196. #ifndef VERBOSE
  1197.      if (winner) printf("%d\n", t), fflush(stdout);
  1198. #endif
  1199.   }
  1200. }
  1201.  
  1202. char nameop(op)
  1203. int op;
  1204. {
  1205.     switch(op)
  1206.     {
  1207.     case MUL: return '*';
  1208.     case DIV: return '/';
  1209.     case ADD: return '+';
  1210.     case SUB: return '-';
  1211.     }
  1212.     return '?';
  1213. }
  1214.  
  1215. float eval(op, val1, val2)
  1216. int op;
  1217. float val1, val2;
  1218. {
  1219.     switch(op)
  1220.     {
  1221.     case MUL: return val1 * val2;
  1222.     case DIV:
  1223.         if (val2 == 0.)
  1224.         {
  1225.             divzero = 1;
  1226. #ifdef EXTREMELYVERBOSE
  1227.             fprintf(stderr, "Division by zero.\n");
  1228. #endif
  1229.         }
  1230.         return val2 == 0.? 0. : val1 / val2;
  1231.     case ADD: return val1 + val2;
  1232.     case SUB: return val1 - val2;
  1233.     }
  1234.     return 0.;
  1235. }
  1236.  
  1237.  
  1238.  
  1239. ==> arithmetic/digits/extreme.products.p <==
  1240. What are the extremal products of three three-digit numbers using digits 1-9?
  1241.  
  1242. ==> arithmetic/digits/extreme.products.s <==
  1243. There is a simple procedure which applies to these types of problems (and
  1244. which can be proven with help from the arithmetic-geometric inequality).
  1245.  
  1246. For the first part we use the "first large then equal" procedure.
  1247. This means that are three numbers will be 7**, 8**, and 9**.  Now
  1248. the digits 4,5,6 get distributed so as to make our three number as
  1249. close to each other as possible, i.e. 76*, 85*, 94*.  The same goes
  1250. for the remaining three digits, and we get 763, 852, 941.
  1251.  
  1252. For the second part we use the "first small then different" procedure.
  1253. Our three numbers will be of the form 1**, 2**, 3**.  We now place
  1254. the three digits so as to make our three numbers as unequal as possible;
  1255. this gives 14*, 25*, 36*.  Finishing, we get 147, 258, 369.
  1256.  
  1257. Now, *prove* that these procedures work for generalizations of this
  1258. problem.
  1259.  
  1260. ==> arithmetic/digits/labels.p <==
  1261. You have an arbitrary number of model kits (which you assemble for
  1262. fun and profit).  Each kit comes with twenty (20) stickers, two of which
  1263. are labeled "0", two are labeled "1", ..., two are labeled "9".
  1264. You decide to stick a serial number on each model you assemble starting
  1265. with one.  What is the first number you cannot stick.  You may stockpile
  1266. unused numbers on already assembled models, but you may not crack open
  1267. a new model to get at its stickers.  You complete assembling the current
  1268. model before starting the next.
  1269.  
  1270. ==> arithmetic/digits/labels.s <==
  1271. The method I used for this problem involved first coming up with a
  1272. formula that says how many times a digit has been used in all n models.
  1273.  
  1274. n = k*10^i + m for some k,m with 0 <k <10, m < 10^i
  1275. f(d,n) = (number of d's used getting to k*10^i from digits 0 to (i-1)) +
  1276.     (number of d's used by #'s 10^i to n from digit i) + f(d,m)
  1277. f(d,n) = i*k*10^(i-1) + (if (d < k) 10^i else if (d == k) m+1 else 0) + f(d,m)
  1278.  
  1279. This doesn't count 0's, which should be ok as they are not used as often
  1280. as other digits.  From the formula, it is clear that f(1,n) is never
  1281. less than f(d,n) for 1<d<10.
  1282. So I just calculated f(1,n) for various n (with some help from bc).
  1283.  
  1284. I quickly discovered that for n = 2*10^15, f(1,n) = 2*n.  After further
  1285. trials I determined that for n = 1999919999999981, f(1,n) = 2*n + 1. 
  1286. This appears to be the smallest n with f(1,n) > 2*n.
  1287.  
  1288. ==> arithmetic/digits/least.significant/factorial.p <==
  1289. What is the least significant non-zero digit in the decimal expansion of n!?
  1290.  
  1291. ==> arithmetic/digits/least.significant/factorial.s <==
  1292. Reduce mod 10 the numbers 2..n and then cancel out the
  1293. required factors of 10. The final step then involves
  1294. computing 2^i*3^j*7^k mod 10 for suitable i,j and k. 
  1295.  
  1296. A small program that performs this calculation is appended. Like the
  1297. other solutions, it takes O(log n) arithmetic operations.
  1298.  
  1299. -kym
  1300. ===
  1301.  
  1302. #include<stdio.h>
  1303. #include<assert.h>
  1304.  
  1305. int    p[6][4]={
  1306.     /*2*/    2,    4,    8,    6,
  1307.     /*3*/    3,    9,    7,    1,
  1308.     /*4*/    4,    6,    4,    6,
  1309.     /*5*/    5,    5,    5,    5,
  1310.     /*6*/    6,    6,    6,    6,
  1311.     /*7*/    7,    9,    3,    1,
  1312.     };
  1313.  
  1314. main(){
  1315.     int    i;
  1316.     int n;
  1317.  
  1318.     for(n=2;n<1000;n++){
  1319.         i=lsdfact(n);
  1320.         printf("%d\n",i);
  1321.         }
  1322.  
  1323.     exit(0);
  1324.     }
  1325.  
  1326. lsdfact(n){
  1327.     int    a[10];
  1328.     int    i;
  1329.     int    n5;
  1330.     int    tmp;
  1331.  
  1332.     for(i=0;i<=9;i++)a[i]=alpha(i,n);
  1333.  
  1334.     n5=0;
  1335. /* NOTE: order is important in following */
  1336. l5:;
  1337.     while(tmp=a[5]){    /* cancel factors of 5 */
  1338.         n5+=tmp;
  1339.         a[1]+=(tmp+4)/5;
  1340.         a[3]+=(tmp+3)/5;
  1341.         a[5]=(tmp+2)/5;
  1342.         a[7]+=(tmp+1)/5;
  1343.         a[9]+=(tmp+0)/5;
  1344.         }
  1345. l10:;
  1346.     if(tmp=a[0]){
  1347.         a[0]=0;    /* cancel all factors of 10 */
  1348.         for(i=0;i<=9;i++)a[i]+=alpha(i,tmp);
  1349.         }
  1350.     if(a[5]) goto l5;
  1351.     if(a[0]) goto l10;
  1352.  
  1353. /* n5 == number of 5's cancelled; 
  1354.    must now cancel same number of factors of 2 */
  1355.     i=ipow(2,a[2]+2*a[4]+a[6]+3*a[8]-n5)*
  1356.         ipow(3,a[3]+a[6]+2*a[9])*
  1357.         ipow(7,a[7]);
  1358.     assert(i%10);    /* must not be zero */
  1359.     return    i%10;
  1360.     }
  1361.  
  1362. alpha(d,n){
  1363. /* number of decimal numbers in [1,n] ending in digit d */
  1364.     int tmp;
  1365.     tmp=(n+10-d)/10;
  1366.     if(d==0)tmp--;    /* forget 0 */
  1367.     return tmp;
  1368.     }
  1369.  
  1370. ipow(x,y){
  1371. /* x^y mod 10 */
  1372.     if(y==0) return 1;
  1373.     if(y==1) return x;
  1374.     return p[x-2][(y-1)%4];
  1375.     }
  1376.  
  1377.  
  1378.  
  1379.  
  1380. ==> arithmetic/digits/least.significant/tower.of.power.p <==
  1381. What are the least significant digits of 9^(8^(7^(6^(5^(4^(3^(2^1))))))) ?
  1382.  
  1383. ==> arithmetic/digits/least.significant/tower.of.power.s <==
  1384. 9^11 = 9 (mod 100), so we need to find 8^...^1 (mod 10).
  1385. 8^5 = 8 (mod 10), so we need to find 7^...^1 (mod 4).
  1386. 7^3 = 7 (mod 4), so we need to find 6^...^1 (mod 2), but
  1387. this is clearly 0, so 7^...^1 = 1 (mod 4) ==>
  1388. 8^...^1 = 8 (mod 10) ==> 9^...^1 = 9^8 (mod 100) = 21 (mod 100).
  1389.  
  1390. ==> arithmetic/digits/most.significant/googol.p <==
  1391. What digits does googol! start with?
  1392.  
  1393. ==> arithmetic/digits/most.significant/googol.s <==
  1394. I'm not sure how to calculate the first googol of digits of log10(e), but
  1395. here's the first 150(approximately) of them...
  1396.  
  1397. 0.43429448190325182765112891891660508229439700580366656611445378316586464920
  1398. 8870774729224949338431748318706106744766303733641679287158963906569221064663
  1399.  
  1400. We need to deal with the digits immediately after the decimal point in
  1401. googol*log10(e), which are  .187061
  1402.  
  1403. frac[log(googol!)] = frac[halflog2pi + 50 + googol(100-log10(e))]
  1404.  = frac{halflog2pi + frac[googol(100-log10(e))]}
  1405.  = frac[.399090 + (1- .187061)]
  1406.  = .212029
  1407.  
  1408. 10 ** .212029 = 1.629405
  1409.  
  1410. Which means that googol! starts with 1629
  1411.  
  1412. ==> arithmetic/digits/most.significant/powers.p <==
  1413. What is the probability that 2^N begins with the digits 603245?
  1414.  
  1415. ==> arithmetic/digits/most.significant/powers.s <==
  1416. 2^N begins with 603245 iff 603246*10^m > 2^N >= 603245*10^m for some
  1417. positive integer m ==> m+log(603246) > N*log(2) >= m+log(603245);
  1418. so 2^N begins with 603245 iff frac(log(603246)) > frac(N*log(2))
  1419. >= frac(log(603245)).  If we are using natural density then N*log(2)
  1420. is uniformly distributed mod 1 since log(2) is irrational, hence the
  1421. probability is frac(log(603246)) - frac(log(603245)) =
  1422. frac(log(603246)-log(603245)) = frac(log(603246/603245)).
  1423.  
  1424. A neat observation is that since it is known p_n*c, where p_n is the
  1425. nth prime and c is irrational, is uniformly distributed mod 1, we get
  1426. the same answer if we replace 2^N with 2^{p_n}.
  1427. -- 
  1428. Chris Long, 265 Old York Rd., Bridgewater, NJ  08807-2618
  1429.  
  1430. ==> arithmetic/digits/nine.digits.p <==
  1431. Form a number using 0-9 once with its first n digits divisible by n.
  1432.  
  1433. ==> arithmetic/digits/nine.digits.s <==
  1434. First, reduce the sample set. For each digit of ABCDEFGHI, such that the last
  1435. digit, (current digit), is the same as a multiple of N :
  1436.  
  1437. A: Any number 1-9
  1438. B: Even numbers 2,4,6,8 (divisible by 2).
  1439. C: Any number 1-9 (21,12,3,24,15,6,27,18,9).
  1440. D: Even numbers 2,4,6,8 (divisible by 4, every other even).
  1441. E: 5 (divisible by 5 and 0 not allowed).
  1442. F: Even numbers (12,24,6,18)
  1443. G: Any number 1-9 (21,42,63,14,35,56,7,28,49).
  1444. H: Even numbers (32,24,16,8)
  1445. I: Any number 1-9 (81,72,63,54,45,36,27,18,9)
  1446.  
  1447. Since E must be 5, I can eliminate it everywhere else.
  1448. Since I will use up all the even digits, (2,4,6,8) filling in those spots
  1449.    that must be even. Any number becomes all odds, except 5.
  1450.  
  1451. A: 1,3,7,9
  1452. B: 2,4,6,8
  1453. C: 1,3,7,9
  1454. D: 2,4,6,8
  1455. E: 5
  1456. F: 2,4,6,8
  1457. G: 1,3,7,9
  1458. H: 2,4,6,8
  1459. I: 1,3,7,9
  1460.  
  1461. We have that 2C+D=0 (mod 4), and since C is odd,
  1462. this implies that D is 2 or 6; similarly we find that H is 2 or 6 ==>
  1463. {B,F} = {4,8}.  D+5+F=0 (mod 3) ==> if D=2 then F=8, if D=6 then F=4.
  1464.  
  1465. We have two cases.
  1466.  
  1467. Assume our number is of the form A4C258G6I0.  Now the case n=8 ==>
  1468. G=1,9; case n=3 ==> A+1+C=0 (mod 3) ==> {A,C}={1,7} ==> G=9, I=3.
  1469. The two numbers remaining fail for n=7.
  1470.  
  1471. Assume our number is of the form A8C654G2I0.  The case n=8 ==> G=3,7.
  1472. If G=3, we need to check to see which of 1896543, 9816543, 7896543, 
  1473. and 9876543 are divisible by 7; none are.
  1474.  
  1475. If G=7, we need to check to see which of 1896547, 9816547, 1836547,
  1476. and 3816547 are divisible by 7; only the last one is, which yields
  1477. the solution 3816547290.
  1478.  
  1479. ==> arithmetic/digits/palindrome.p <==
  1480. Does the series formed by adding a number to its reversal always end in
  1481. a palindrome?
  1482.  
  1483. ==> arithmetic/digits/palindrome.s <==
  1484. This is not known.
  1485.  
  1486. If you start with 196, after 9480000 iterations you get a 3924257-digit
  1487. non-palindromic number.  However, there is no known proof that you will
  1488. never get a palindrome.
  1489.  
  1490. The statement is provably false for binary numbers. Roland Sprague has
  1491. shown that 10110 starts a series that never goes palindromic.
  1492.  
  1493. ==> arithmetic/digits/palintiples.p <==
  1494. Find all numbers that are multiples of their reversals.
  1495.  
  1496. ==> arithmetic/digits/palintiples.s <==
  1497. We are asked to find numbers that are integer multiples of their
  1498. reversals, which I call palintiples.  Of course, all the palindromic
  1499. numbers are a trivial example, but if we disregard the unit multiples,
  1500. the field is narrowed considerably.
  1501.  
  1502. Rouse Ball (_Mathematical_recreations_and_essays_) originated the
  1503. problem, and G. H. Hardy (_A_mathematician's_apology_) used the result
  1504. that 9801 and 8712 are the only four-digit palintiples as an example
  1505. of a theorem that is not ``serious''.  Martin Beech (_The_mathema-
  1506. tical_gazette_, Vol 74, #467, pp 50-51, March '90) observed that
  1507. 989*01 and 879*12 are palintiples, an observation he ``confirmed'' on
  1508. a hand calculator, and conjectured that these are all that exist.
  1509.  
  1510. I confirm that Beech's numbers are palintiples, I will show that they
  1511. are not all of the palintiples.  I will show that the palintiples do
  1512. not form a regular language.  And then I will prove that I have found
  1513. all the palintiples, by describing the them with a generalized form
  1514. of regular expression.  The results become more interesting in other
  1515. bases.
  1516.  
  1517. First, I have a more reasonable method of confirming that these
  1518. numbers are palintiples:
  1519.  
  1520.     Proof:  First, letting "9*" and "0*" refer an arbitrary string of
  1521.     nines and a string of zeroes of the same length, I note that
  1522.  
  1523.         879*12 = 879*00 + 12 = (880*00 - 100) + 12 = 880*00 - 88
  1524.         219*78 = 219*00 + 78 = (220*00 - 100) + 78 = 220*00 - 22
  1525.  
  1526.         989*01 = 989*00 +  1 = (990*00 - 100) +  1 = 990*00 - 99
  1527.         109*89 = 109*00 + 89 = (110*00 - 100) + 89 = 110*00 - 11
  1528.  
  1529.     It is obvious that 4x(220*00 - 22) = 880*00 - 88 and that
  1530.     9x(110*00 - 11) = 990*00 - 99.  QED.
  1531.  
  1532. Now, to show that these palintiples are not all that exist, let us
  1533. take the (infinite) language L[4] = (879*12 + 0*), and let Pal(L[4])
  1534. refer to the set of palindromes over the alphabet L[4].  It is
  1535. immediate that the numbers in Pal(L[4]) are palintiples.  For
  1536. instance,
  1537.  
  1538.           8712 000 87912 879999912 879999912 87912 000 8712
  1539.     = 4 x 2178 000 21978 219999978 219999978 21978 000 2178
  1540.  
  1541. (where I have inserted spaces to enhance readability) is a palintiple.
  1542. Similarly, taking L[9] = (989*01 + 0*), the numbers in Pal(L[9]) are
  1543. palintiples.  We exclude numbers starting with zeroes.
  1544.  
  1545. The reason these do not form a regular language is that the
  1546. sub-palintiples on the left end of the number must be the same (in
  1547. reverse order) as the sub-palintiples on the right end of the number:
  1548.  
  1549.          8712 8712 87999912 = 4 x 2178 2178 21999978
  1550.  
  1551. is not a palintiple, because 8712 8712 87999912 is not the reverse of
  1552. 2178 2178 21999978.  The pumping lemma can be used to prove that
  1553. Pal(L[4])+Pal(L[9]) is not a regular language, just as in the familiar
  1554. proof that the palindromes over a non-singleton alphabet do not form a
  1555. regular language.
  1556.  
  1557. Now to characterize all the palintiples, let N be a palintiple,
  1558. N=CxR(N), where R(.) signifies reversal, and C>1 is an integer.  (I
  1559. use "x" for multiplication, to avoid confusion with the Kleene star
  1560. "*", which signifies the concatenated closure.)  If D is a digit of N,
  1561. let D' refer to the corresponding digit of R(N).  Since N=CxR(N),
  1562. D+10T = CxD'+S, where S is the carry in to the position occupied by D'
  1563. when R(N) is multiplied by C, and T is the carry out of that position.
  1564. Similarly, D'+10T'=CxD+S', where S', T' are carries in and out of the
  1565. position occupied by D when R(N) is multiplied by C.
  1566.  
  1567. Since D and D' are so closely related, I will use the symbol D:D' to
  1568. refer to a digit D on the left side of a string with a corresponding
  1569. digit D' on the right side of the string.  More formally, an
  1570. expression "x[1]:y[1] x[2]:y[2] ... x[n]:y[n] w" will refer to a
  1571. string "x[1] x[2] ... x[n] w y[n] ... y[2] y[1]", where the x[i] and
  1572. y[i] are digits and w is a string of zero or one digits.  So 989901
  1573. may be written as 9:1 8:0 9:9 and 87912 may be written as 8:2 7:1 9.
  1574. Thus Pal(L[4])+Pal(L[9]) (omitting numbers with leading zeroes) can be
  1575. represented as
  1576.  
  1577.             (8:2 7:1 9:9* 1:7 2:8 0:0*)*
  1578.               (0:0* + 0 + 8:2 7:1 ( 9:9* + 9:9* 9))
  1579.           + (9:1 8:0 9:9* 0:8 1:9 0:0*)*
  1580.               (0:0* + 0 + 9:1 8:0 ( 9:9* + 9:9* 9)).      (1)
  1581.  
  1582. For each pair of digits D:D', there are a very limited--and often
  1583. empty--set of quadruples S,T,S',T' of digits that satisfy the
  1584. equations
  1585.  
  1586.                     D +10T =CxD'+S
  1587.                     D'+10T'=CxD +S',                      (2)
  1588.  
  1589. yet such a quadruple must exist for "D:D'" to appear in a palintiple
  1590. with multiplier C.  Furthermore, the S and T' of one D:D' must be T
  1591. and S', respectively, of the next pair of digits that appear.  This
  1592. enables us to construct a finite state machine to recognize those
  1593. palintiples.  The states [X#Y] refer to a pair of carries in D and D',
  1594. and we allow a transition from state [T#S'] to state [S#T'] on input
  1595. symbol D:D' exactly when equations (2) are satisfied.  Special
  1596. transitions for a single-digit input symbol (the central digit of
  1597. odd-length palintiples) and the criteria for the initial and the
  1598. accepting states are left as exercises.  The finite state machines
  1599. thus formed are
  1600.  
  1601.    State         Symbol  New     Symbol  New      Symbol   New
  1602.         Accept?         State           State             State
  1603.  
  1604. --> [0#0]  Y       8:2  [0#3]      0:0  [0#0]         0   [A]
  1605.     [0#3]  N       7:1  [3#3]
  1606.     [3#3]  Y       1:7  [3#0]      9:9  [3#3]         9   [A]
  1607.     [3#0]  N       2:8  [0#0]
  1608.      [A]   Y
  1609.  
  1610. for constant C=4, and
  1611.  
  1612.    State         Symbol  New     Symbol  New      Symbol   New
  1613.         Accept?         State           State             State
  1614.  
  1615. --> [0#0]  Y       1:9  [0#8]      0:0  [0#0]         0   [A]
  1616.     [0#8]  N       8:0  [8#8]
  1617.     [8#8]  Y       0:8  [8#0]      9:9  [8#8]         9   [A]
  1618.     [8#0]  N       9:1  [0#0]
  1619.      [A]   Y
  1620.  
  1621. for constant C=9, and the finite state machines for other constants
  1622. accept only strings of zeroes.  It is not hard to verify that the
  1623. proposed regular expression (1) represents the union of the languages
  1624. accepted by these machines, omitting the empty string and strings
  1625. beginning with zero.
  1626.  
  1627. I have written a computer program that constructs finite state
  1628. machines for recognizing palintiples for various bases and constants.
  1629. I found that base 10 is actually an unusually boring base for this
  1630. problem.  For instance, the machine for base 8, constant C=5 is
  1631.  
  1632.    State         Symbol  New     Symbol  New      Symbol  New
  1633.         Accept?         State           State            State
  1634.  
  1635. --> [0#0]  Y       0:0  [0#0]      5:1  [0#3]         0  [A]
  1636.     [0#3]  N       1:0  [1#1]      6:1  [1#4]
  1637.     [1#1]  Y       0:1  [3#0]      5:2  [3#3]
  1638.     [3#0]  N       1:5  [0#0]      6:6  [0#3]         6  [A]
  1639.     [3#3]  Y       2:5  [1#1]      7:6  [1#4]
  1640.     [1#4]  N       1:1  [4#1]      6:2  [4#4]         1  [A]
  1641.     [4#4]  Y       2:6  [4#1]      7:7  [4#4]         7  [A]
  1642.     [4#1]  N       1:6  [3#0]      6:7  [3#3]
  1643.      [A]   Y
  1644.  
  1645. for which I invite masochists to write the regular expression.  If
  1646. anyone wants more, I should remark that the base 29 machine for
  1647. constant C=18 has 71 states!
  1648.  
  1649. By the way, I did not find any way of predicting the size or form of
  1650. the machines for the various bases, except that the machines for C=B-1
  1651. all seem to be isomorphic to each other.  If anyone investigates the
  1652. general behavior, I would be most happy to hear about it.
  1653.  
  1654. Dan Hoey
  1655. Hoey@AIC.NRL.Navy.Mil
  1656. May, 1992
  1657. [ A preliminary version of this message appeared in April, 1991. ]
  1658. ================================================================
  1659. Dan
  1660.  
  1661.  
  1662.  
  1663. ==> arithmetic/digits/power.two.p <==
  1664. Prove that for any 9-digit number (base 10) there is an integral power
  1665. of 2 whose first 9 digits are that number.
  1666.  
  1667. ==> arithmetic/digits/power.two.s <==
  1668. Let v = log to base 10 of 2.
  1669. Then v is irrational.
  1670.  
  1671. Let w = log to base 10 of these 9 digits.
  1672.  
  1673. Since v is irrational, given epsilon > 0, there exists some natural number 
  1674. n such that
  1675.  
  1676.    {w} < {nv} < {w} + epsilon
  1677.  
  1678. ({x} is the fractional part of x.)  Let us pick n for when 
  1679.  
  1680.    epsilon = log 1.00000000000000000000001.
  1681.  
  1682. Then 2^n does the job.
  1683.  
  1684. ==> arithmetic/digits/prime/101.p <==
  1685. How many primes are in the sequence 101, 10101, 1010101, ...?
  1686.  
  1687. ==> arithmetic/digits/prime/101.s <==
  1688. Note that the sequence
  1689. 101 , 10101, 1010101, ....
  1690. can be viewed as 
  1691. 100**1 +1, 100**2 + 100**1 + 1, 100**3 + 100**2 + 100**1 +1 ....
  1692. that is, 
  1693. the k-th term in the sequence is 
  1694. 100**k + 100**(k-1) + 100**(k-2) + ...+ 100**(1) + 1
  1695. = (100)**(k+1) - 1
  1696.   ----------------
  1697.     11 * 9
  1698. = (10)**(2k+2) - 1
  1699.   ----------------
  1700.     11 * 9
  1701. = ((10)**(k+1) - 1)*((10)**(k+1) +1)
  1702.    ---------------------------------
  1703.        11*9
  1704. thus either 11 and 9 divide the numerator. Either they both divide the
  1705. same factor in the numerator or different factors in the numerator. In
  1706. any case, after dividing, they leave the numerators as a product of two
  1707. integers.  Only in the case of k = 1, one of the integers is 1. Thus
  1708. there is exactly one prime in the above sequence: 101.
  1709.  
  1710. ==> arithmetic/digits/prime/all.prefix.p <==
  1711. What is the longest prime whose every proper prefix is a prime?
  1712.  
  1713. ==> arithmetic/digits/prime/all.prefix.s <==
  1714. 23399339, 29399999, 37337999, 59393339, 73939133
  1715.  
  1716. ==> arithmetic/digits/prime/change.one.p <==
  1717. What is the smallest number that cannot be made prime by changing a single
  1718. digit?  Are there infinitely many such numbers?
  1719.  
  1720. ==> arithmetic/digits/prime/change.one.s <==
  1721. 200.  Obviously, you would have to change the last digit, but 201, 203,
  1722. 207, and 209 are all composite.  For any smaller number, you can change
  1723. the last digit, and get
  1724. 2,11,23,31,41,53,61,71,83,97,101,113,127,131,149,151,163,173,181, or 191.
  1725.  
  1726. 200+2310n gives an infinite family, because changing the last
  1727. digit to 1 or 7 gives a number divisible by 3; to 3, a number divisible
  1728. by 7; to 9, a number divisible by 11.
  1729.  
  1730. ==> arithmetic/digits/prime/prefix.one.p <==
  1731. 2 is prime, but 12, 22, ..., 92 are not.  Similarly, 5 is prime
  1732. whereas 15, 25, ..., 95 are not.  What is the next prime number
  1733. which is composite when any digit is prefixed?
  1734.  
  1735. ==> arithmetic/digits/prime/prefix.one.s <==
  1736. 149
  1737.  
  1738. ==> arithmetic/digits/reverse.p <==
  1739. Is there an integer that has its digits reversed after dividing it by 2?
  1740.  
  1741. ==> arithmetic/digits/reverse.s <==
  1742. Assume there's such a positive integer x such that x/2=y and y is the
  1743. reverse of x.
  1744.  
  1745. Then x=2y.  Let x = a...b, then y = b...a, and:
  1746.  
  1747.                  b...a   (y)
  1748.            x     2
  1749.                --------
  1750.                  a...b   (x)
  1751.  
  1752. From the last digit b of x, we have b = 2a (mod 10), the possible
  1753. values for b are 2, 4, 6, 8 and hence possible values for (a, b) are
  1754. (1,2), (6,2), (2,4), (7,4), (3,6), (8,6), (4,8), (9,8).
  1755.  
  1756. From the first digit a of x, we have a = 2b or a = 2b+1.  None of the
  1757. above pairs satisfy this condition.  A contradiction.
  1758.  
  1759. Hence there's no such integer.
  1760.  
  1761. ==> arithmetic/digits/rotate.p <==
  1762. Find integers where multiplying them by single digits rotates their digits
  1763. one position, so that the last digit become the first digit.
  1764.  
  1765. ==> arithmetic/digits/rotate.s <==
  1766. 2 105263157894736842
  1767. 3 1034482758620689655172413793
  1768. 4 102564 153846 179487 205128 230769
  1769. 5 142857 102040816326530612244897959183673469387755
  1770. 6 1016949152542372881355932203389830508474576271186440677966
  1771.   1186440677966101694915254237288135593220338983050847457627
  1772.   1355932203389830508474576271186440677966101694915254237288
  1773.   1525423728813559322033898305084745762711864406779661016949
  1774. 7 1014492753623188405797 1159420289855072463768 1304347826086956521739
  1775. 8 1012658227848 1139240506329
  1776. 9 10112359550561797752808988764044943820224719
  1777.  
  1778. In base B, suppose you have an N-digit answer A whose digits are
  1779. rotated when multiplied by K.  If D is the low-order digit of A, we
  1780. have
  1781.  
  1782.     (A-D)/B + D B^(N-1) = K A .
  1783.  
  1784. Solving this for A we have
  1785.  
  1786.         D (B^N - 1)
  1787.     A = ----------- .
  1788.           B K - 1
  1789.  
  1790. In order for A >= B^(N-1) we must have D >= K.  Now we have to find N
  1791. such that B^N-1 is divisible by R=(BK-1)/gcd(BK-1,D).  This always has
  1792. a minimal solution N0(R,B)<R, and the set of all solutions is the set
  1793. of multiples of N0(R,B).  N0(R,B) is the length of the repeating part
  1794. of the fraction 1/R in base B.
  1795.  
  1796. N0(ST,B)=N0(S,B)N0(T,B) when (S,T)=1, and for prime powers, N0(P^X,B)
  1797. divides (P-1)P^(X-1). Determining which divisor is a little more
  1798. complicated but well-known (cf. Hardy & Wright).
  1799.  
  1800. So given B and K, there is one minimal solution for each
  1801. D=K,K+1,...,B-1, and you get all the solutions by taking repetitions
  1802. of the minimal solutions.
  1803.  
  1804. ==> arithmetic/digits/sesqui.p <==
  1805. Find the least number where moving the first digit to the end multiplies by 1.5.
  1806.  
  1807. ==> arithmetic/digits/sesqui.s <==
  1808. Let's represent this number as  a*10^n+b,  where 1<=a<=9 and
  1809. b < 10^n.  Then the condition to be satisfied is:
  1810.  
  1811. 3/2(a*10^n+b) = 10b+a
  1812.  
  1813.   3(a*10^n+b) = 20b+2a
  1814.  
  1815.    3a*10^n+3b = 20b+2a
  1816.  
  1817.   (3*10^n-2)a = 17b
  1818.  
  1819.             b = a*(3*10^n-2)/17
  1820.  
  1821. So we must have 3*10^n-2 = 0 (mod 17) (since a is less than 10, it
  1822. cannot contribute the needed prime 17 to the factorization of 17b).
  1823. (Also, assuming large n, we must have a at most 5 so that b < 10^n will
  1824. be satisfied, but note that we can choose a=1).  Now,
  1825.  
  1826. 3*10^n-2 = 0 (mod 17)
  1827.  
  1828. 3*10^n = 2 (mod 17)
  1829.  
  1830. 10^n = 12 (mod 17)
  1831.  
  1832. A quick check shows that the smallest n which satisfies this is 15
  1833. (the fact that one exists was assured to us because 17 is prime).  So,
  1834. setting n=15 and a=1 (obviously) gives us b=176470588235294, so the
  1835. number we are looking for is
  1836.  
  1837.                         1176470588235294
  1838.  
  1839. and, by the way, we can set a=2 to give us the second smallest such
  1840. number,
  1841.                         2352941176470588
  1842.  
  1843. Other things we can infer about these numbers is that there are 5 of
  1844. them less than 10^16, 5 more less than 10^33, etc.
  1845.  
  1846. ==> arithmetic/digits/squares/change.leading.p <==
  1847. What squares remain squares when their leading digits are incremented?
  1848.  
  1849. ==> arithmetic/digits/squares/change.leading.s <==
  1850. Omitting solutions that are obtained from smaller solutions by
  1851. multiplying by powers of 10, the squares of these numbers satisfy the
  1852. condition:
  1853.  
  1854. 1. (105,145), (3375,4625), (14025,17225), (326625,454625),
  1855.     (10846875,14753125), (43708125,53948125), ...
  1856.  
  1857. 2. (45,55), (144375,175625), (463171875,560828125), ...
  1858.  
  1859. 7. (2824483699753370361328125,2996282391593370361328125), ...
  1860.  
  1861. Here is how to find them. We have (y+x)*(y-x) = 10^n, and so we must have 
  1862. {y+x, y-x} as {5^m*10^a, 2^m*10^b} in some order. It is also necessary (and
  1863. sufficient) that y/x lies in the interval [sqrt(3/2),sqrt(2)], or equivalently
  1864. that (y+x)/(y-x) lies in [3+sqrt(8),5+sqrt(24)] = [5.82842...,9.89897...].
  1865. Thus we need to make (5/2)^m*10^(a-b), or its reciprocal, in this range.
  1866. For each m there is clearly at most one power of 10 that will do. m=2,a=b
  1867. gives (105,145); m=3,b=a+2 gives (3375,4625), and so on.
  1868.  
  1869. There are infinitely many non-equivalent solutions, because log(5/2) / log(10)
  1870. is irrational.
  1871.  
  1872. One can use exactly the same argument to find squares whose initial 2 can 
  1873. be replaced by a 3, of course, except that the range of (y+x)/(y-x) changes.
  1874.  
  1875. ==> arithmetic/digits/squares/length.22.p <==
  1876. Is it possible to form two numbers A and B from 22 digits such that
  1877. A = B^2?  Of course, leading digits must be non-zero.
  1878.  
  1879. ==> arithmetic/digits/squares/length.22.s <==
  1880. No, the number of digits of A^2 must be of the form 3n or 3n-1.
  1881.  
  1882. ==> arithmetic/digits/squares/length.9.p <==
  1883. Is it possible to make a number and its square, using the digits from 1
  1884. through 9 exactly once?
  1885.  
  1886. ==> arithmetic/digits/squares/length.9.s <==
  1887. Yes, there are two such pairs: (567, 567^2=321489) and (854,854^2=729316).
  1888.  
  1889.