Phantom's Python Challenge

View as PDF

Submit solution


Points:30 (partial)
Time limit:4.0s
Memory limit:512M
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 30 staggering points.

Input Specification

The input will be one line, containing the number N, such that N \in \{50, 100, 1\,000, 1\,000\,000, 10\,000\,000\}.

Output Specification

All the primes smaller than N, separated by whitespace, with a * after every number forming a twin prime with another. A twin prime is defined as a prime number n such that n-2 or n+2 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 160 characters long. More accurately, you get (\frac{160}{L})^2 \times 20 + 10 points, capped at 30, where L is the length of your solution, if it is correct.

Sample Input

50

Sample Output

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

Comments


  • 0
    echofox
     commented on Sept. 25, 2017 edited

    e: help


    • 2
      Xyene
       commented on Sept. 25, 2017

      Work on it for more than 2 hours 😃


      • 0
        echofox
         commented on Sept. 25, 2017

        blasphemy :o


  • 0
    Epicnerdking
     commented on April 5, 2016 edited
    Can we use lambda?

    Never mind :), great problem btw!


  • 2
    GaryZ
     commented on April 7, 2015
    There goes my evening :P

    Thanks for the fun problem, guys!


    • 4
      FatalEagle
       commented on April 7, 2015

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


    • 0
      quantum
       commented on April 7, 2015

      Good job. Now try to make it even shorter!


      • 3
        GaryZ
         commented on April 7, 2015

        Too late, I peeked at your code.


  • 0
    quantum
     commented on Dec. 17, 2014
    Memory limit increased to 256M

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


  • 0
    quantum
     commented on Nov. 30, 2014
    Scoring Change

    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.