spoj

Shortest code in C

Problem Statement : Sum the positive values in a series of integers. Input : t – number of test cases [t < 1000]. On each of next t lines given a integer N [-1000 <= N <= 1000] Output : One integer equals to sum of all positive integers. This is actually a SPOJ problem.I had solved it using python & ruby already but now I am interes...

CODE1 Spoj - cannot solve it

I am trying to solve the problem Secret Code and it's obviously math problem. The full problem For those who are lazy to go and read, it's like this: a0,a1,a2,...,an - sequence of N numbers B - some number known to us X = a0 + a1*B + a2*(B^2) + a3*(B^3) + ... + an*(B^n) So if you are given B and X, you should find a0,a1,..an. I don...

PRIME1 problem in SPOj. i get a SIGSEGV error y?pls help me out

#include<stdio.h> main() { long long int m,n,i,j; int t; scanf("%d",&t); while(t--) { scanf("%lld",&m); scanf("%lld",&n); long long int a[n+2]; for(i=0;i<=n;i++) { a[i]=1; } for(i=2;i<=sqrt(n);i++) { j=2; while((i*j)<=n) ...

How to get REALLY fast python over a simple loop

Edit2: I finally got it to pass at 10.54 seconds. I used nearly all of your answers to get there and thus it was hard to choose one as 'correct' but I believe the one I chose sums it up the best. Thanks to you all. Final passing code is below. Edit: I included some of the suggested updates in the included code. I'm working on a spo...

Help making this code run faster for spoj.

I've been doing a few of the challenges on the Sphere Online Judge, but I can't seem to get the second problem (the prime generator) to run within the time limit. Does anyone have any tips for increasing the speed of the following code? #include <stdio.h> #include <math.h> int is_prime(int n); void make_sieve(); void fast_prime(int n);...

Avoid NZEC error in erlang in SPOJ

I ve written code in erlang and i am getting correct answer in my machine. But when i am submitting it in spoj.pl it is giving nzec(non zero exit code) error. I have used inbuilt functions like halt() and init:stop() and their specification clearly says that they are used to avoid non zero exit code error.But still i am geting same error...

Haskell in SPOJ: "Wrong answer" in problem, but correct in my computer

Hi I've been submitting solutions to the COINS problem in SPOJ today. I've got accepted the Fortran and the Perl solutions, but I'm having "Wrong answer" in the Haskell solution. I thought that perhaps my code was faulty at some point, but the results for 200K numbers (100K in the upper limit and 100K in the lower one) are exactly as pe...

Shortest way to print "Success"

I have been trying this problem SUCCESS at spoj but I am not able to get optimal solution to that problem I tried int main(){return !puts("Success");} but it takes 45 characters. Any alternate suggestions to solve the problem? People have solved it using 24 characters also. ...

SPOJ ADDREV Problem

Guys, got the answer in C ; THank you for all the help . Hey , I did go through the other threads on this(ADDREV Problem )(https://www.spoj.pl/problems/ADDREV/ ) but sadly, i am not able to get an answer by any of the three programs that i have written. ( in C , python and java ) . I am attaching the code snippets of all three. T...

Time Limit Exceeded ->Python , SPOJ, Prime Generator

Hi ,the URL of the problem is ( https://www.spoj.pl/problems/PRIME1/) yeah i did go through some thread about having time limit exceeded. I am using Python 2.6.4 . IDLE . The code is here : def prime(a): count=0 for i in range(2,int(math.sqrt(a))): if(a%i==0): count=count+1 if(count==0): return...

My Sieve of Eratosthenes takes too long

I have implemented "sieve of eratosthenes" to solve an SPOJ problem. Though the output is fine, my submission exceeds the time limit. How can I reduce the run time? int main() { vector<int> prime_list; prime_list.push_back(2); vector<int>::iterator c; bool flag=true; unsigned int m,n; for(int i=3; i<=32000;i+=2) { flag...