case = int(input())
TM = 1000*1000*10
factors = [0] * (TM + 1)
def getFactorsBrute(hi):
for div in range(1, hi+1):
multiple = div
while multiple <= hi:
factors[multiple] += 1
multiple += div
return 0
for i in range(case):
n, lo, hi = map(int, input().strip().split(' '))
getFactorsBrute(hi)
cnt = 0
for i in range(lo, hi+1):
if factors[i] == n:
cnt += 1
print(cnt)
Declare factors[] externally and use factors[] in getFactorsBrute. Repeat the first for statement as much as the case and use factors I wonder how you can get the factors you want without initializing them every time.
python
# For an integer from 1 to hi+1
for div in range(1, hi+1):
# I assigned that number to the multiple variable
multiple = div
while multiple <= hi:
# In the factors list, you can import elements with multiple indexes into factors [multiple].
factors[multiple] += 1
multiple += div
© 2024 OneMinuteCode. All rights reserved.