You are viewing a single comment's thread. Return to all comments →
Something wrong with my solution. Can't understand what. It does not passed a couple of tests within timeout error:
import math
q = int(input().rstrip())
for _ in range(q): a, b = map(int, input().rstrip().split())
pn = 1 if b/a > 10000: pn = int(math.log(int(b/a),2)) - 1 if pn < 1: pn = 1 start_p2 = 2**pn if pn > 1: start_p2 -=1 start_num_1 = pn
num_1 = start_num_1 cur_p2 = start_p2 k = 2 prev_curp2 = cur_p2 while 1: num_1 += 1 cur_p2 = 2*cur_p2 if (num_1-1)*b < a*(cur_p2 - 2): k = math.floor(((num_1-1)*b)/a + 2 - cur_p2) + cur_p2 while (num_1-1)*b < a*(cur_p2 - 2 - k - 1) and (cur_p2 - k - 1 >= prev_curp2): k -= 1 break prev_curp2 = cur_p2 k_sum = k**2 - k print("{}".format(k_sum)) prev_curp2 = cur_p2 k_sum = k**2 - k print("{}".format(k_sum))
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #207: Integer partition equations
You are viewing a single comment's thread. Return to all comments →
Something wrong with my solution. Can't understand what. It does not passed a couple of tests within timeout error:
import math
q = int(input().rstrip())
for _ in range(q): a, b = map(int, input().rstrip().split())
pn = 1 if b/a > 10000: pn = int(math.log(int(b/a),2)) - 1 if pn < 1: pn = 1 start_p2 = 2**pn if pn > 1: start_p2 -=1 start_num_1 = pn