We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
short c++ solution.
the main idea is that we can calculate how many pages to turn to get number 'x' by turning 'x//2' pages (divide with rounding down e.g. 5//2 = 2). It's because on every display of 2 pages there are 2 consecutive pages e.g. (2,3), (3,4) etc. All we gotta do is just see if we can get from 0->p by turning p//2 pages or from n->p which is n//2-p//2.
Drawing Book
You are viewing a single comment's thread. Return to all comments →
short c++ solution. the main idea is that we can calculate how many pages to turn to get number 'x' by turning 'x//2' pages (divide with rounding down e.g. 5//2 = 2). It's because on every display of 2 pages there are 2 consecutive pages e.g. (2,3), (3,4) etc. All we gotta do is just see if we can get from 0->p by turning p//2 pages or from n->p which is n//2-p//2.