fb pixel

Introduction to Python

  • Profound Academy

    • Status
      • 1
        Input and Output
      • 2
        Variables and Integer Arithmetic
      • 3
        Conditional Operators
      • 4
        Advanced Conditions - Nesting
      • 5
        Types and Variables
      • 6
        Strings
      • 7
        Lists
      • 8
        For Loops
      • 9
        While Loops
      • 10
        continue, break, while...else
      • 11
        String and List methods
      • 12
        Nested Loops
      • 13
        List Comprehension
      • 14
        Tuples and Sets
      • 15
        dict
      • 16
        Functions
      • 17
        Functions 2
      • 18
        Lambda and higher-order functions
      • 19
        Files

  • Elimination game

    Let’s play a game. There are n people who think of a random number. They don’t know the rules of the game. Only you do. You know that at each step of the game, the people who have kept a number with the least number of divisors, get out of the game. You ask everyone their numbers and then you should tell who’s going to leave the game on each step. They should guess the rule of the game. Now your task is to write a program that simulates the game and prints the names of people who’ll leave the game at each step.
    The first line of the input contains a single integer n which is the number of people participating in the game. The next n lines contain the names of participants and the number they’ve memorized. It’s guaranteed that the names are unique and the numbers are positive.
    The program should print the name of people leaving the game at each stage of the game.
    Input
    Output
    5 Anna 6 Bob 8 Simon 1 Karen 10 Lucy 100
    Simon Anna Bob Karen Lucy
    Explanation:
    Anna 6 (1, 2, 3, 6) ⇒ 4 divisors
    Bob 8 (1, 2, 4, 8) ⇒ 4 divisors
    Simon 1 (1) ⇒ 1 divisor
    Karen 10 (1, 2, 5, 10) ⇒ 4 divisors
    Lucy 100 (1, 2, 4, 5, 10, 20, 25, 50, 100) ⇒ 9
     
    To check your solution you need to sign in
    Sign in to continue