第三题,非打表

4 views
Skip to first unread message

王希元

unread,
Jan 2, 2019, 5:13:22 AM1/2/19
to cs10...@googlegroups.com
m,n=map(int,input().split())
a=[]
b=0
for i in range(m):
    a.append([int(i)for i in input().split()])
    b=max(max(a[-1]),b)
b=int(b**0.5)
p=[True for i in range(2,b+1)]
prime=set()
for k in range(2,b+1):
    if p[k-2]:
        prime.add(k)
        t=k+k
        while t<b+1:
            p[t-2]=False
            t+=k
for r in a:
    l=len(r)
    total=sum(filter(lambda x:x**0.5 in prime,r))
    print(0 if total==0 else '{:.2f}'.format(total/l))
Reply all
Reply to author
Forward
0 new messages