## Phantom's Python Challenge

View as PDF

Points: 40 (partial)
Time limit: 1.8s
Memory limit: 768M

Author:
Problem type
Allowed languages
Python

After all the ordeal, Christine decided to save your lives by kissing the Phantom. That was very nice of her. However, the Phantom considers letting Christine leave with Raoul, if and only if you can convince him that your party is worthy. He challenges you to write a program that shows all the primes under a specific number, while marking the twin primes. Easy as it may sound, the Phantom is also an expert programmer: you have to prove yourself to be at least as good as him. In Python, he expects you to write it in one statement. This means, no new lines or semi-colons are allowed. To prevent the cheap way of achieving this, you are also not allowed to use eval or exec. To make sure he did not save that scarf for nothing, Raoul bribes you with 40 staggering points.

#### Input Specification

The input will be one line, containing the number , such that .

#### Output Specification

All the primes smaller than , separated by whitespace, with a * after every number forming a twin prime with another. A twin prime is defined as a prime number such that or are prime.

#### Scoring

If your solution is correct and contains only one statement without eval or exec, you get 10 points. For full points, your solution must be at most 118 characters long.

More accurately, let be the length of your solution. If your solution is wrong, you receive 0. If , you get points. If , your score is .

#### Sample Input

50

#### Sample Output

2
3*
5*
7*
11*
13*
17*
19*
23
29*
31*
37
41*
43*
47

• commented on April 11, 2020, 4:41 p.m.

Is the full solution possible in python 3? All of the best submissions are in python 2.

• commented on April 9, 2020, 8:58 p.m.

Note: As an extension of eval/exec cheating, compile is also not allowed.

• commented on Jan. 23, 2019, 11:41 a.m. edit 2

Looking from the sample input, are we assuming that 1 is a prime as well since 3 is considered a twin prime?

• commented on Nov. 27, 2017, 6:54 p.m.

Help please. What's causing my code to MLE? sys.getsizeof(set([*range(int(1e7))])), the maximum size of my sieve, returns 134217844 130MB on my computer. Why is my code using so much more than that?

• commented on Nov. 27, 2017, 7:06 p.m.

Pypy, despite fast is not very efficient with memory.

• commented on Nov. 27, 2017, 7:19 p.m.

My code TLEs on PY3 but would otherwise still MLE.

• commented on Sept. 25, 2017, 1:49 p.m. edited

e: help

• commented on Sept. 25, 2017, 2:39 p.m.

Work on it for more than 2 hours 😃

• commented on Sept. 25, 2017, 7:00 p.m.

blasphemy :o

• commented on April 5, 2016, 5:21 p.m. edited

Never mind :), great problem btw!

• commented on April 7, 2015, 11:44 p.m.

Thanks for the fun problem, guys!

• commented on April 7, 2015, 11:52 p.m.

Never did I think I would see the day someone actually solves this problem.

• commented on April 7, 2015, 11:47 p.m.

Good job. Now try to make it even shorter!

• commented on April 7, 2015, 11:51 p.m.

Too late, I peeked at your code.

• commented on Dec. 17, 2014, 10:48 p.m.

Increased memory limit to 256M. This will allow the problem to be solvable on 64-bit judges.

• commented on Nov. 30, 2014, 12:44 p.m.

Due to my discovery of an 146 character solution, the old character limit of 220 no longer makes any sense. Therefore, the full score solution now requires 160 characters.

This problem is now out of 30 points so that any old score will not decrease.