 Tags IOS SQL HTML C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 # Lambda function for calculating sum of primes

By : Tom
Date : September 15 2020, 07:00 AM
it fixes the issue 1. first error: "TypeError: 'generator' object is not callable"
this error raise because you pass to filter build-in method a generator, you "cover" the lambda method with parentheses: code :
``````filter((lambda n: n%y != 0 for y in range(2,n)), range(2,n+1))
``````
``````filter(lambda n: n%y != 0 for y in range(2,n), range(2,n+1))
``````
``````lambda n: n%y != 0 for y in range(2,n)
``````
``````lambda n: all(n%y != 0 for y in range(2,n))
``````
``````sum=0
``````
``````n_prime_sum = 0
``````
``````n = int(input())

n_prime_sum = 0
n_prime_sum = sum(list(filter(lambda n: all(n%y != 0 for y in range(2,n)), range(2,n+1))))
n_prime_sum
# n = 10
``````
``````17
``````
``````# original code by David Eppstein, UC Irvine, 28 Feb 2002
# with comments by Eli Bendersky, https://stackoverflow.com/a/568618

def gen_primes(n):
"""Much more efficient prime generation, the Sieve of Eratosthenes"""

D = {}

q = 2   # The running integer that's checked for primeness

while q <= n:
if q not in D:
# q is a new prime.
# Yield it and mark its first multiple that isn't
# already marked in previous iterations
#
yield q
D[q * q] = [q]
else:
# q is composite. D[q] is the list of primes that
# divide it. Since we've reached q, we no longer
# need it in the map, but we'll mark the next
# multiples of its witnesses to prepare for larger
# numbers
for p in D[q]:
D.setdefault(p + q, []).append(p)
del D[q]

q += 1

n = int(input())
n_prime_sum = sum(gen_primes(n))
print(n_prime_sum)
# n = 10
``````
``````17
``````

## How do I use BigInterger In my code for calculating primes?

By : test user
Date : March 29 2020, 07:55 AM
it helps some times Do you really need this? Having numbers bigger than can be handled by long means you want to test numbers bigger than 9223372036854775807. If your for-loop can test a hundred million divisions per second, it will still take it 2923 years to determine if that number is prime - and longer for larger numbers, of course.
A common optimization is to only test divisions up to sqrt(num). If you haven't found anything then, the number is prime.

## Program Calculating The Logs of Primes

By : Daniel Branco
Date : March 29 2020, 07:55 AM
it fixes the issue Your second list doesn't only contain the logs of primes, it contains the logs of all integers between 2 and lp.

## Calculating primes from 1 to n -- Crash

By : Alexey Zaslavsky
Date : March 29 2020, 07:55 AM
around this issue I've writen some code in C that calculates all the prime numbers from 1 to n (n is input from user). , Your 'i' and 'x' both start from 0. So when you do

## Lua - Calculating Primes from 1 to n

By : ChosenWell
Date : March 29 2020, 07:55 AM
around this issue The loop prints out a number if isPrime is true, but isPrime gets set to false when you check the value 4, and nothing ever sets it to true again.

## Problem with calculating Primes within a given Range in C++

By : Toby Jones
Date : March 29 2020, 07:55 AM
Hope that helps Im trying to create a program that does various math operations, and i wanted to start with calculating prime numbers within a given range. However, when i try to execute the code, it just returns exit status -1. What is wrong with the program and how do i fix it? , this loop should start from 2 because :
code :
``````for (int c = 2; c < num; c++) {
if (num % c == 0) {
num_of_factors++;
}
}
`````` 