【发布时间】:2014-04-16 04:51:34
【问题描述】:
我无法降低这个问题的复杂性。请提供一些更好的方法。
是否有我不知道的数学公式,或者可以用更好的方法来完成?
说明:
A special number is not divisible by any number of the form Z*Z where (Z>1).
问题:求给定范围内特殊数字的个数。
Integer Limit:10^9
我是这样做的:
import math
def special(x):
flag=1
i=2
if(x==0 or x==1 or x==2):
return 1
while(i*i <= x): //This is the best i can think to limit the numbers.
if(x%(i*i)==0):
flag=0
break
i=i+1
return flag
t=int(raw_input())
while(t):
x,y=map(int,raw_input().split())
count=0
for i in xrange(x,y+1):
if(special(i)):
count+=1
print(count)
t=t-1
【问题讨论】:
-
是的..它的重复。感谢您的链接。