We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Project Euler #10: Summation of primes
Project Euler #10: Summation of primes
Sort by
recency
|
216 Discussions
|
Please Login in order to post a comment
Did it with DIctionary Generated primes initially and added their sum.
t = int(input().strip()) for a0 in range(t): n = int(input().strip()) l=[2] for i in range(3,n+1,2): r=1 for j in l: if i%j==0: r=0 break if r: l.append(i)
print(sum(l))
its stilll showing timeout, how can i optimize it further??
My script in python was as follows:
It passed all tests. I implemented an equivalent approach in Rust but received timeout errors for 6 and 7. Any ideas?
Haskell
include
include
include
using namespace std; bool isprime(long number){ if((number != 2 && number != 3 && number != 5) && (number % 2 == 0 || number % 3 == 0 || number % 5==0))
}
int main(){ vector primes; for(long i = 2; i<1000000; i++){ if (isprime(i)) primes.push_back(i); }
}