Hey guys, 
Hope you all are doing great. I am back with another problem of Project Euler on

The sum of the primes below  is 
Find the sum of all the primes not greater than given .
Input Format
The first line contains an integer  i.e. number of the test cases.
The next  lines will contains an integer .
Output Format
Print the value corresponding to each test case in separate line.
Constraints

Sample Input
2
5
10
Sample Output
10
17

Algorithm:

The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Implement this algorithm, with the only allowed optimization that the outer loop can stop at the square root of the limit, and the inner loop may start at the square of the prime just found. That means especially that you shouldn't optimize by using pre computed wheels, i.e. don't assume you need only to cross out odd numbers (wheel based on 2), numbers equal to 1 or 5 modulo 6 (wheel based on 2 and 3), or similar wheels based on low primes.

Odds-only version of the array sieve above
The below code uses only odd composite operations (for a factor of over two) and because it has been optimized to use slice operations for composite number culling to avoid extra work by the interpreter

Program:



def primes2(limit):
    if limit < 2: return []
    if limit < 3: return [2]
    lmtbf = (limit - 3) // 2
    buf = [True] * (lmtbf + 1)
    for i in range((int(limit ** 0.5) - 3) // 2 + 1):
        if buf[i]:
            p = i + i + 3
            s = p * (i + 1) + i
            buf[s::p] = [False] * ((lmtbf - s) // p + 1)
    return sum([2] + [i + i + 3 for i, v in enumerate(buf) if v])

t=input()
while(t>0):
    print primes2(input())
    t-=1

Hope you liked this post.
Do let me know about any improvements i can incorporate to anything in the blog.

Till Then...Cheers!!


0

Add a comment

Greetings!! Here's a series of Cold Golf problems and solutions in Python as a part of 21 days of Code | Code Golf by Skillenza 

https://skillenza.com/challenge/21days-of-code

DAY - I

A Little Complex

Given n complex numbers each x + yi, where x is the real part and y is the imaginary part, find their product.

Input Format

The first line of input consists of an integer t denoting the number of test cases. t test cases follow.
1

For the need of a simple tabular Grid in your Angular JS application, one of the most basic and simple to use package is angular-ui-grid. The implementation is easy in many of the use cases, but when it comes to extend the limits of the ui-grid, life becomes tough.

One of the tricky task is to set the Grid height as dynamic, in other words to make the grid more flexible to number of rows and the grid size would depend on it.

Hey guys, Hope you all are doing great. 

Algorithm To Convert Post-fix Expression into Infix expression:-

Scan the Post-fix String from Left to Right. If the character is an Operand, then Push it on to the deque. If the character is an Operator, then Pop left Operator 1 and Operand 2 and concatenate them using Infix notation where the Operator is in between the Two Operands. The resultant expression is then pushed on the deque.

Hey guys, Hope you all are doing great.

As the first part of this series of Python package and installation we will cover pip vs Conda

pip vs Conda

pip

Python packages only. Compiles everything from source. Installs binary, wheel, the ones which pypi supply Blessed by the core Python community (i.e., Python 3.4+ includes code that automatically boostraps pip). conda

Python agnostic.

Hey guys,

Hope you all are doing great. I love Code Golfing, what it brings out in you is the hidden concepts of a programming language and especially the push to implement same thing in numerous ways.

Code Golfing and Python - Yeah that's my Poison!

Below are few tips and tricks which will give you an edge over other programmer to write the shortest code:

1. The foo if condition else bar condition can be shortened to

True if condition else False ------- [False,True][condition]

2.

Hey guys, Hope you all are doing great.

I have always found Regular expressions or REGEX quite amazing. You can solve your string related problem in just some simple magic of patterns.

Our brain works very well to identify the pattern in our day to day life. As these are visual clues, we tend to catch and analyse them better. In fact, their you make negligible mistake to tackle the scenario.
1

Hey guys, Hope you all are doing great. I am back with Some Python Programming tips for

CODE GOLF Challenges.

Here are the Second part of code golfing Tips in Python

I prefer Python or Python3 myself for code golfing

So we will discuss dome tips as generics for code golf programming in Python:

7. Use `n` to convert an integer to a string instead of using str(n).

Hey guys, Hope you all are doing great. I am back with Some Python Programming tips for

CODE GOLF Challenges.

So, What is CODE GOLF??

As per Wikipedia, it is a type of recreational computer programming competition in which participants strive to achieve the shortest possible source code (not to be confused with binary Sizecoding) that implements a certain algorithm.
12

Hey guys, Hope you all are doing great. I am back with with a byte of python performance.

I have been playing on codingame.com a lot now a days during my weekends.

Its cool site for the player aka coders who want to try there hands into gaming domain.
Loading