蓝桥杯刷题--python-36

4199. 公约数 - AcWing题库

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 ansmid<=R:l=mid

else: r=mid-1

if ansr>=L:

print(ansr)

else:

print("-1")

相关推荐
IT龟苓膏34 分钟前
并发深度解析】硬核手撕 ForkJoinPool + WorkStealing + CompletableFuture 底层源码与大厂面试演练
面试·职场和发展
心软小念6 小时前
2026软件测试高频面试题
软件测试·面试·职场和发展
洛水水1 天前
【力扣100题】86.柱状图中最大的矩形
算法·leetcode·职场和发展
洛水水1 天前
【力扣100题】85.每日温度
算法·leetcode·职场和发展
海绵宝宝的月光宝盒1 天前
6-机械设计基础物理知识
经验分享·笔记·其他·职场和发展·课程设计·学习方法
_日拱一卒1 天前
LeetCode:22括号生成
算法·leetcode·职场和发展
枫子有风1 天前
LLM-RAG(大厂面试常问问题)
面试·职场和发展·llm·rag
洛水水1 天前
【力扣100题】84.字符串解码
算法·leetcode·职场和发展
嵌入式ZYXC1 天前
第9篇:《面试题:ADC前端为什么要加运放跟随器?什么情况下可以不加?》
stm32·单片机·嵌入式硬件·面试·职场和发展
洛水水1 天前
【力扣100题】90.寻找重复数
算法·leetcode·职场和发展