Post Reply 
[VA] SRC #008 - 2021 is here !
01-03-2021, 06:33 PM (This post was last modified: 02-16-2021 01:38 AM by robve.)
Post: #6
RE: [VA] SRC #008 - 2021 is here !
Thanks for posting. A good motivation to write some code on HP Prime. You did not mention that RPN is required...

#1 I couldn't find a way to run HP Prime programs with bigint (only up to 64bit), so the full decimal result is computed and displayed with HP Prime CAS in the code below.

Here is another puzzle: Compute the smallest set(s) of square numbers that sum up to 2021. In other words, what are the sets of fewest square numbers that sum up to 2021 such that each square number is used at most once?

For example, 1+9+36 sums up to 46 and 1=1^2, 9=3^2, 36=6^2 are square numbers. The size of this set is three, which is minimal since no two square numbers sum up to 46. Another solution is 1+4+16+25=46, but that solution has four square numbers and thus is not a minimal set.

There may be multiple minimal sets of square numbers for 2021. A set is minimal if no other set exists that is smaller.



Since we want to write some code, let's verify that powers of 3 give the max,
by brute force trying all products from 2 to sqrt(2021).
We use log here, which means we can simply sum up instead of using products,
e.g. to prevent overflow on some calculators (but HP Prime handles large floats.)

EXPORT T2021()
BEGIN
  LOCAL N := 2021, M := 0, J, K, R, X;
  FOR I FROM 2 TO SQRT(N) DO
    K := FLOOR(N/I);
    R := N-K*I;
    IF R=0 THEN
      R := 1;
    END;
    X := K*LN(I)+LN(R);
    IF X>M THEN
      M := X;
      J := I;
    END;
  END;
  MSGBOX(J);
  MSGBOX(e^M);
END;

After playing with this, it is interesting that 3 is best.
The reason is that 3 is close to the number e, which you can easily see is the best number to pick, because we have that
N/3*LN(3)<N/e
and
N/2*LN(2)<N/e
for any N>0 e.g. N=2021. Graphing N/x*LN(x) shows x=e is optimal.

The full number is displayed in HP Prime CAS:

2*3^673

25329955218868262923281496551277939397110796485699809049268130708906002579675557​8
80841323830523234581366754082537819748828642552123142645059118075006593388245733​4
55569632621982327471866288083832732135816196262336795334877060602534949818961126​6
4520885716630483899029142003916544644957076791520721759240671604739781810307846

"I count on old friends" -- HP 71B,Prime|Ti VOY200,Nspire CXII CAS|Casio fx-CG50...|Sharp PC-G850,E500,2500,1500,14xx,13xx,12xx...
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] SRC #008 - 2021 is here ! - Gene - 01-02-2021, 01:49 AM
RE: [VA] SRC #008 - 2021 is here ! - robve - 01-03-2021 06:33 PM
RE: [VA] SRC #008 - 2021 is here ! - robve - 01-05-2021, 03:39 AM
RE: [VA] SRC #008 - 2021 is here ! - Gene - 01-04-2021, 05:56 PM
RE: [VA] SRC #008 - 2021 is here ! - Gene - 01-04-2021, 07:24 PM
RE: [VA] SRC #008 - 2021 is here ! - Gene - 01-06-2021, 02:54 PM
RE: [VA] SRC #008 - 2021 is here ! - EdS2 - 01-08-2021, 01:32 PM



User(s) browsing this thread: 1 Guest(s)