Sort by

recency

|

19 Discussions

|

  • + 0 comments

    My Python code that passed all the test cases:

    def solve(S):  # S = initial strength
        mod_n = 10**9 + 7
        if S%20 != 0:
            return ((S//20)*42 + (S%20)*2) % mod_n  
        else:
            return ((S//20)*42 - 2) % mod_n
    
  • + 0 comments

    Am I the only person who read "divisible by 4 and/or 2 but not divisible by 42" as "(divisible by 4) and/or (divisible by 2 but not divisible by 42)" rather than "(divisible by 4 and/or 2) but (not divisible by 42)"? The second is apparently the correct interpretation (which cost a few Hackos to find out), but in that case the 4 is redundant. With the first interpretation, we don't get the "bonus" steps at the even multiples of 42 (which actually makes it a slightly more interesting question).

    A little bit of rewording on this question might help clear up the potential confusion.

  • + 1 comment

    Python 3 Solution :

    def solve(s):
        n = 21*s//10 - 1
        for i in range(5):
            if n % 2 == 0 and n//2-n//42 == s:
                return n % (1000*1000*1000+7)
            n += 1
    
    
    for _ in range(int(input())):
        print(solve(int(input())))
    
  • + 0 comments

    Assume that the shark has gone till he has reached the square number n and there, his strength has became 0 .

    We know that n have to be divisible by 2 . The number of squares that are divisible by 2 and <= n is floor ( n/2 ) .

    The number of squares divisible by 42 is floor ( n / 42 ) .

    Here we want the number of squares divisible by 2 and not divisible by 42. Though we have floor (n/2) - floor(n/42) = s .

    To solve this equation, you can write it in the form without floor functions (( n/2 + n/42 = s )) .

    Then solve this equation. Let the answer to be x. First take the integer part of x.

    Then set x as x-10. At last, run a loop from 0 to 20 and in each iteration, increment x.

    After incrementing, check if x%2 ==0 and floor(x/2)-floor(x/42) == s .

    The first x that satisfies the constraints is the answer.

    Sorry for my bad English.

  • + 0 comments

    This can be thought of as a fenceposting issue.

    That is, take some amount of s (try a few examples, like 21, 22, 40, 41, 42, 61 hint hint) and see how far you go.

    Even further, think about how, if you have gotten to square 42, you get to square 44, what is the next multiple of 42 you'll reach? How much strength is required to get there from 44 (what square will you actually end on whith that exact amount of strength?). Does a pattern emerge after that? Remember, this is a math problem; doing it iteratively is wasteful.