813B - The Golden Age - CodeForces Solution


brute force math *1800

Please click on ads to support us..

Python Code:


import math
import os
import random
import re
import sys


    


if __name__ == '__main__':
    
    x,y,l,r = list(map(int, input().rstrip().split()))
    
    arr = []
    a,b = 1,1

    while a<r:
        b = 1
        while a+b<=r:
            if l <= a+b and a+b <= r:
                arr.append(a+b)
            b *= y 
        a *= x
    ans = 0
    arr += [l-1,r+1]
    arr.sort()
        for i in range(1,len(arr)):
        ans = max(ans,arr[i]-arr[i-1]-1)
    print(ans)


Comments

Submit
0 Comments
More Questions

361A - Levko and Table
5E - Bindian Signalizing
687A - NP-Hard Problem
1542C - Strange Function
961E - Tufurama
129D - String
888A - Local Extrema
722B - Verse Pattern
278A - Circle Line
940A - Points on the line
1742C - Stripes
1742F - Smaller
1742B - Increasing
1742A - Sum
1742D - Coprime
390A - Inna and Alarm Clock
1398B - Substring Removal Game
1742G - Orray
416B - Art Union
962A - Equator
803B - Distances to Zero
291A - Spyke Talks
1742E - Scuza
1506D - Epic Transformation
1354G - Find a Gift
1426F - Number of Subsequences
1146B - Hate "A"
1718C - Tonya and Burenka-179
834A - The Useless Toy
1407D - Discrete Centrifugal Jumps