Cerinta completa

There is a strange counter. At the first second, it displays the number . Each second, the number displayed by decrements by until it reaches . In next second, the timer resets to and continues counting down. The diagram below shows the counter values for each time in the first three cycles:

Find and print the value displayed by the counter at time .

Function Description

Complete the strangeCounter function in the editor below.

strangeCounter has the following parameter(s):

  • int t: an integer

Returns

  • int: the value displayed at time

Input Format

A single integer, the value of .

Constraints

Subtask

  • for of the maximum score.

Sample Input

4

Sample Output

6

Explanation

Time marks the beginning of the second cycle. It is double the number displayed at the beginning of the first cycle:. This is shown in the diagram in the problem statement.


Limbajul de programare folosit: python3

Cod:

#!/bin/python3

def strangeCounter(t):
    start = 1
    val = 3
    while t > start + val - 1:
        start += val
        val *= 2
    return val - (t - start)

if __name__ == '__main__':
    t = int(input().strip())
    print(strangeCounter(t))

Scor obtinut: 1.0

Submission ID: 464589504

Link challenge: https://www.hackerrank.com/challenges/strange-code/problem

Strange Counter