def gcd(a,b):
while b:
a,b=b,a%b
return a
def init_divisors(a,b):
d=gcd(a,b)
i=1
while i*i<=d:
if d%i==0:
ans.append(i)
if i!=d//i:ans.append(d//i)
i+=1
ans.sort()
a,b=map(int,input().split())
ans=[]
init_divisors(a,b)
q=int(input())
for _ in range(q):
L,R=map(int,input().split())
l=0;r=len(ans)-1
while (l<r):
mid=l+r+1>>1
if ans[mid]<=R:l=mid
else: r=mid-1
if ans[r]>=L:
print(ans[r])
else:
print("-1")
蓝桥杯刷题--python-36
芝士小熊饼干2024-04-07 16:04
相关推荐
元亓亓亓2 天前
LeetCode热题100--105. 从前序与中序遍历序列构造二叉树--中等测试老哥2 天前
Selenium 使用指南仙俊红2 天前
LeetCode每日一题,20250914前端小超超3 天前
capacitor配置ios应用图标不同尺寸睡不醒的kun3 天前
leetcode算法刷题的第三十四天吃着火锅x唱着歌3 天前
LeetCode 1446.连续字符武子康3 天前
AI-调查研究-76-具身智能 当机器人走进生活:具身智能对就业与社会结构的深远影响Nan_Shu_6144 天前
Web前端面试题(1)YuTaoShao4 天前
【LeetCode 每日一题】3000. 对角线最长的矩形的面积007php0074 天前
Redis高级面试题解析:深入理解Redis的工作原理与优化策略