10
votes
6answers
3k views

Sum of all primes under 2 million

I have this assignment to write the optimized space and time code for finding the sum of all primes under 2 million in c/c++. Im using the following function to check if each number is prime ...
5
votes
3answers
115 views

Go Aaaaaaaaaaah

The problem is described in full here - Aaah!. Input The input consists of two lines. The first line is the “aaah” Jon Marius is able to say that day. The second line is the “aah” the ...
5
votes
2answers
84 views

Genomic Range Query

Recently I worked on one of the Codility Training - Genomic Range Query (please refer to one of the evaluation report for the detail of this training). The proper approach for this question is using ...
4
votes
3answers
151 views

Penney Game - mapping macros to strings

The SPOJ problem: Given a 40 character string representing outcomes of 40 coin tosses, find the frequency destribution of all the possible outcome triplets. So, for string like : HHHH....40 Hs ...
4
votes
1answer
296 views

Why is this divide and conquer algorithm inefficient?

I was solving one of the problem in USACO 2007 Open Silver: Description Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the city horizon and observe ...
4
votes
3answers
199 views

Please review my solution to Project Euler program 1

Can someone give me suggestions on how to improve this program? The objective is to find the sum of all the multiples of 3 or 5 below 1000. ...
4
votes
3answers
65 views

String self-similarity

It's a string problem I have been making on Hackerrank. It is executing fine on all test cases except the last two. These last two test case are declaring it "Terminated due to time out". C programs ...
4
votes
1answer
32 views

Basic Reverse Polish CL Parser

K and R Exercise 5-10 Write the program expr, which evaluates a reverse Polish expression from the command line, where each operator or operand is a separate argument. For example, ...
3
votes
1answer
264 views

Function to find sum of digits in the number a^b where a, b are positive integers

I was solving Project Euler problem 16, which asks to find the sum of digits of the number 2 raised to the power 1000. Using Python, it can be solved in one line of code: ...
3
votes
2answers
192 views

Project Euler #1 - Multiples of 3 and 5

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. ...
2
votes
1answer
47 views

Two squares or not two squares - constant time optimization

I have been trying to solve this problem, and after a bit of googling, I realised a \$O(\sqrt{n})\$ time complexity works fine (though the algorithm suggested is different from that I have used). My ...
1
vote
1answer
71 views

Square free Integer

I am an amateur programmer and I tried coding this problem using the TurboC++ IDE (though my code is in C), but the site's compiler throws a "TIME LIMIT EXCEEDED" error. How can I optimize my code ...
1
vote
1answer
306 views

Can this solution to Project Euler #15 be improved?

I'm not a C programmer, just wanted to make a fast solution to the problem. Here's my code: ...
1
vote
2answers
40 views

Skiena's Programming Challenges: The Trip problem

I have the following solution for the Trip problem from Skiena's and Revilla's Programming Challenges (full problem description here). ...
0
votes
1answer
51 views

Why is this code giving me a wrong answer? [closed]

I have solved this problem in C, but I get wrong answer every time, could you maybe tell me what I did wrong? Also, don't laugh at my code, I started learning C 7 days ago :) ...