看板 Python 關於我們 聯絡資訊
最近也在練習python 不過我寫得好長orz c==1的情況就不處理了=.=a def checkPrime(n, pList): prime = True for p in pList: if p*p > n: break if n % p == 0: prime = False break if prime == True: pList.append(n) return True return False def getPrime(c): primeList = [] primeList.append(2) primeList.append(3) c -= 2 count = 0 i = 1 while count < c: num = 6 * i - 1 if checkPrime(num, primeList): count += 1 if count >= c: break num = 6 * i + 1 if checkPrime(num, primeList): count += 1 i += 1 return primeList if __name__ == '__main__': print getPrime(40) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.47.75.8