Translate

Views

Saturday, December 28, 2024

Solution UVA: 10940 - Throwing cards away II

 

Problem  VerdictLangTimeBestRankSubmit Time
 | discuss10940 - Throwing cards away II AcceptedPython1.2600.00037065 mins ago


Suggest:

- After readed problem, We feel problem need find a rule to solve

- How to find a rule in competitive programming ?

- Often we need show many result from min n


Col: A = input, B = output

Rule:

- If input is 2^x, we have output = input

- Else output is y_current = y_previous + 2  


Code Python:

b = 0
a = 2
d = {}

while True:
    e = a**b
    if e > 500000:
        break
   
    d[e] = True
    b += 1

v = 2
r = {}

for i in range(1, 500000):
    if i in d:
        v = 2
        r[i] = i    
    else:
        r[i] = v
        v += 2

while True:
    n = int(input())
    if n == 0:
        break
    print(r[n])