第一题二分查找

7 views
Skip to first unread message

王希元

unread,
Jan 2, 2019, 5:05:09 AM1/2/19
to cs10...@googlegroups.com
n=int(input())
a=[int(i)for i in input().split()]
b=max(a)
c=[i*i for i in range(1,b)]
def check(x):
    global c
    m=0
    n=len(c)-1
    while n>=m:
        now=c[m]+c[n]
        if now==x:
            return True
        elif now>x:
            n-=1
        elif now<x:
            m+=1
    return False
a=filter(check,a)
for r in a:
    print('0b{:0b} 0o{:0o} 0x{:0x}'.format(r,r,r))
Reply all
Reply to author
Forward
0 new messages