我试图使用Python 2.7.9作为我的编码语言来解决SPOJ上的TWOSQRS问题,并设计了一个程序来解决这个问题。由于代码可以完美运行,因此在给定测试用例输入的情况下,不会在我的系统上引发任何异常。如果有人可以为我提供更多的测试用例或在我的代码中找到错误,那将是有帮助的。
链接到问题:http : //www.spoj.com/problems/TWOSQRS/
# -*- coding: utf-8 -*-
'''To solve the problem 2 primary condition that should be met are:
1. No should not be of the form 4k+3 as for sum of square of two nos will always be of form 4k or 4k+1
2. All the prime factors of form 4k+3 should have even power from the Fermat thorem.
Steps involved in solving the problem are:
1. Sieve a list of prime nos. upto 1000001 as in problem.
2. Check if all the prime factors has even powers.
3. Check if the no is not of form 4k+3'''
import numpy
def sieve(n):
""" An implementation that sieves separately
for primes of the form 6i−1 and 6i+1, due to Robert William Hanks"""
prime = numpy.ones(n//3 + (n%6==2), dtype=numpy.bool)
for i in range(3, int(n**.5) + 1, 3):
if prime[i // 3]:
p = (i + 1) | 1
prime[ p*p//3 ::2*p] = False
prime[p*(p-2*(i&1)+4)//3::2*p] = False
result = (3 * prime.nonzero()[0] + 1) | 1
result[0] = 3
return numpy.r_[2,result]
primes=sieve(10**6+1) #List of all the prime upto 10**6
def main():
noOfCase=input()
for i in range(noOfCase):
N=input()
is_multiple= True
i = 0
while(primes[i]*primes[i] <= N):
count = 0;
while (N % primes[i] == 0):
count+=1;
N/= primes[i];
if (primes[i]%4 == 3 and count%2 == 1):
is_multiple = False;
break;
i+=1
if (N%4 == 3):
is_multiple = False
if(is_multiple):
print "Yes"
else:
print "No"
main()
您的问题几乎可以肯定是您使用的是NumPy,但是选择了不支持它的Python集群/版本。
正如PYTHON:您应该了解的那样,Pyramid群集没有针对任何Python版本的NumPy,Cube群集针对所有CPython版本但没有PyPy版本。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句