import sys import random sys.setrecursionlimit(1500) def prime(n): """ Generate all prime numbers less than n. """ yield 2 primes =  for m in range(3,n,2): if all(m%p for p in primes): primes.append(m) yield m n=int(raw_input()) i=0 j=0 while(n!=-1): p=list(prime(n)) sun=0 while(sun!=n and i<1000000000000000000000000000000): F=random.sample(p,4) sun=sum(F) i+=1 if(sun==n): for i in F: if(j==3): print i else: print i, j+=1 else: print 'Impossible.' n=int(raw_input()) i=0
Time Limit: 4 seconds
Euler proved in one of his classic theorems that prime numbers are infinite in number. But
can every number be expressed as a summation of four positive primes? Your tutors dont know
the answer. May be you can help!!! I want your solution to be very efficient as we have inefficient
machines in the honours lab. The definition of a prime number for this problem is, A prime
number is a positive number which has exactly two distinct integer factors. As for example 37
is prime as it has exactly two distinct integer factors 37 and 1.
The input contains one integer number N (N<=10000000) in every line. This is the number you
will have to express as a summation of four primes. Input is terminated by end of file.
For each line of input there is one line of output, which contains four prime numbers according to
the given condition. If the number cannot be expressed as a summation of four prime numbers
print the line “Impossible.” in a single line. There can be multiple solutions. Any good solution
will be accepted.Your program should run in a continuous loop until a ‘-1’ is entered.
2.4 Sample Input:
2.5 Sample Output:
3 11 3 7
3 7 13 13
11 11 17 7
my code take too long so exceed time limit.can any body help i am new at python