PSBC Project 1
Due 5pm Tuesday, March 5th 2019
Question 1: The Euler-Mascheroni constant
The Euler-Mascheroni constant de ned as
= limn!1lnn+nXk=11k!
0:577215664901533
is a mathematical constant frequently arising in number theory and special integrals. Despite its
appearance in many seemingly unrelated integrals and functions, the EulerMascheroni constant
remains a mystery and is not as well-known as other mathematical constants like . Basic
questions like whether it is irrational or not are still open. In many situations, it is more
convenient to approximate complicated constants like this by the quotient of integers. Find
the best such approximations p=q such that jp=q j is smallest among all possible positive
integers p and q such that p+q is smaller than or equal to a given positive integer.
Task: Write a function AppEM such that [p,q] = AppEM(N) returns the best pair of integers
p and q, such that p+q is less than or equal to N. Record your result for N = 2019.
Note: you can just copy the above value of the constant with fteen decimal points, other-
wise you have to call the symbolic constant and convert it into double precision: em const =
double(eulergamma). The rst few lines of your code look like:
1 function [p,q] = AppEm(N)
2 % APPEM Approximate the Euler-Mascheroni constant by the rational
3 % number p/q, among all pairs of positive integers (p,q) such that p+q
<=N
4
5 em_const = 0.577215664901533;
Remark: (1) you can assume that N is a positive integer greater than one and there is no need
to check the validity of the input; (2) if there are more than one pairs of numbers (for instance,
when the input integer N is 6, both pairs [1;2] and [2;4] give the best approximation), return
the pair with the smallest p+q.
Question 2: Lucky number
An integer n is said to be lucky, if it has only odd prime factors that are distinct (thus at
least two factors), and for any of its prime factor p, p 1 divides n 1. For example,
a136 Any prime number is not lucky, because it has only one prime factor (itself)
1
a136 The number 6 = 2 3 is not lucky, because there is an even factor 2
a136 The number 45 = 3 3 5 is not lucky, because the prime factor 3 appears twice (not
distinct)
a136 The number 15 = 3 5 is not lucky, because 4(= 5 1) does not divide 14(= 15 1)
a136 The number 10585 = 5 29 73 is lucky, because all the prime factors (5, 29 and 73)
are odd and distinct, and
10584
4 =
10585 1
5 1 = 2646;
10584
28 =
10585 1
29 1 = 378;
10584
72 =
10585 1
73 1 = 147:
Write a function luckynum such that luckynum(N) returns the smallest lucky number greater
than or equal to N. Record your output for N = 2019. The rst few lines of your code look like:
1 function n = luckynum(N)
2 % LUCKYNUM Find the smallest lucky number that is greater than or equal to N
Hint: check the numbers equal to or greater than N one by one, and stop when the candidate
number is veri ed to be lucky.
Question 3: Perfect numbers
An integer n is said to be perfect, if its square consists all nine non-zero digits exactly once.
Examples include 11826 and 30384, since
118262 = 139854276; 303842 = 923187456:
Find the perfect number n, such that n2 is closest to 360322019.
1 function n = PerfNum(N)
2 % PERFNUM returns n, such that n^2 is a perfect square number with all nine
distinct digits from 1 to 9,
3 % which is closest to the input N, another nine digits number (can be
assumed to be between 10^9 and 10^10-1)
Information about the coding
a136 Ask the lecturer or the lab demonstrators, if you need help on any commands, or whether
there are built-in commands/functions to accomplish certain tasks (especially important
if you think you have a good approach to the questions, but do not know the related
commands).
a136 You can assume that the input argument is always a positive integer, and no need to
validate the input.
a136 The default datatype is double (decimal number), and be aware of possible side e ects
when using the numbers as integers.
2
a136 Remember that the same question can be solved by di erent approaches, and the same
approach can be implemented in di erent ways. All relevant commands should be covered
during the lectures or tutorial exercises, but you are free to explore own. Make critical
judgement to choose the best approach/implementation.
a136 Aim for e ciency of the code, which is an additional marking criteria, besides the generic
rubric. Although you only need to record the answer for the given input, make sure
that the computational time or memory does not increase signi cantly with larger input
parameters (these issues will be mentioned constantly during the class demonstrations).
a136 List the complete code of the whole function at the end of each question, or in an appendix.
Make your source code more readable, by keeping the indentation and stylistic features,
and can be copied from the electronic le. Your result should be reproduced from the
code attached.
Guidelines for the report
1. Have a look at the generic rubric about how your report will be marked against, and also
the intended learning outcomes about what you are expected to achieve in the end.
2. Avoid copying (too many) sentences directly from the project description, and try to
restate the problem with your own words or examples if possible.
3. You may use your report in the future as evidences of written work, so take it seriously.
4. Your target audience is a fellow student on your course: explain the questions so that
the report can be understood without this project description and your approach can
be implemented in another computer language like Python. The report should indicate
to the reader how well you understand the problem and the approach you take. Your
goal will be to communicate your solutions to another person rather than to show you’ve
completed the assignment.
5. Balance the explanation of the approach and the comments in the code. Avoid under-
commenting and over-commenting.
6. Aim for precision and clarity of writing (discussed in Week 5).
7. Keep your page length not exceeding eight A4 pages, and there is no need for a title page
for a relative short report like this.
8. Since there is no nal exam, you are advised to spend at least 15 hours on each project.
9. All reports are marked anonymously, and there is no need to put any personal information
on the report.
10. The submission for each project will be open two weeks before the deadline, and you are
encouraged to submit an early draft to see how Turnitin works on Blackboard. Only your
last submission will be marked, and DO NOT submit anything after the deadline. Any
late penalty will be applied by the Teaching and Learning O ce in June according to the
Undergraduate Student Handbook, and any extension has to be approved from the O ce
too (not from the lecturer).