Skip to main content

All Questions

2 votes
2 answers
425 views

Can I further optimize this solution for HackerRank's “Making Candies”?

My C++ solution for HackerRank's "Making Candies" problem, reproduced below, is as optimized as I can make it and appears similar to what others say are optimal solutions. However, six of ...
Ray Hamel's user avatar
  • 268
2 votes
3 answers
115 views

Efficiently calculate the value of an arithmetic sequence

I need to calculate the value for the following function: $$f(n) = -1 + 2 - 3 + ... + -1^n$$ The time limit to calculate a given value of \$n\$ is less than 1 second. My approach does not meet that ...
CouldnoT B-Zone's user avatar
3 votes
1 answer
80 views

Finding the lowest perfect square that can be added to a number to make another perfect square

The code below returns the smallest perfect square that can be added to a number n to result in a perfect square. It works perfectly fine but I need it to run ...
Martin 's user avatar
1 vote
1 answer
96 views

Sum of number's quotients when divided by exact powers of 2

Problem I have written code to solve this challenge: Given a formula: GCD(x,y) means the GCD (Greatest Common Divisor) of x and y. For example: if N=2, then: f(2) = 1/GCD(1, 4) + 2/GCD(2, 4) + 3/...
Andra's user avatar
  • 113
2 votes
2 answers
172 views

Project Euler, Problem 273: finding perfect-square partitions

Problem: Consider equations of the form: \$a^2 + b^2 = N; 0 \leq a \leq b; a, b, N \in \mathbb{N}\$. For \$N=65\$ there are two solutions: \$a=1, b=8\$ and \$a=4, b=7\$. We call \$S(...
Alex Hal's user avatar
8 votes
3 answers
1k views

Balanced centrifuge configurations

Given an input N as the size of a centrifuge, I need to find out the number of balanced configurations. The full description is here. Centrifuge is a piece of ...
Kristada673's user avatar
8 votes
1 answer
330 views

Find "prime polynomials" for a user's given prime, bounds, and degree

Very amateur programmer and first-time poster here. The program I wrote asks the user for a prime number, a lower and upper bound, and a degree (all of these are integers). I want to generate a list ...
Gizmo's user avatar
  • 183
5 votes
2 answers
3k views

Project Euler Problem 21 in Python: Summing amicable numbers

Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b ...
RKJ's user avatar
  • 87
5 votes
3 answers
2k views

Find smallest number of squares that sum to a number

Leetcode problem 279 “Perfect Squares” is: Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) I wrote the following solution: ...
loremIpsum1771's user avatar
3 votes
1 answer
159 views

Sum the remainders of ai%aj given an array "a"

Given an array of numbers, I am creating a table where, the cell at the intersection of row i and column j contains a number ai % aj. Numbers in the array can occur multiple times. Example: For ...
Prashanth kumar's user avatar
5 votes
2 answers
869 views

HackerRank - Non-Divisible Subset

In this problem we are asked: Given a set, S, of n distinct integers, print the size of a maximal subset, S', of where the sum of any two numbers in it is not evenly divisible by k. Code My idea is ...
Blasco's user avatar
  • 783
3 votes
2 answers
155 views

Search for solutions to quartic diophantine equation

I wrote this code to find the variables that will satisfy the diophantine equation (i.e. a^4 + b^4 + c^4 = d^4), for all variables belong to: (0 , 430000), and it takes forever to find the answer (I ...
Youssef Ashraf's user avatar
2 votes
2 answers
465 views

Modular sum of square numbers in C++

So I've got an assignment which sounds like this: Given a number n, calculate the result of this sum, modulo 10,234,573: 12 + 22 + 32 + … + n2 This is what I've come up with : ...
Semetg's user avatar
  • 167
9 votes
3 answers
7k views

Odd divisor summation

Given an integer, k, we define its odd divisor sum to be the sum of all k's odd divisors. For example, if k = 20, then the odd divisor sum would be 1 + 5 = 6. Similarly, if given an array of values, ...
CatIntheHatter's user avatar
2 votes
1 answer
2k views

Finding the maximum GCD of all pairs

The code below is for Hackerrank competition. Seems that it works correctly but performs very slowly and because of it can't pass some tests. The task is to find the maximum GCD of all possible pairs ...
Neyroman's user avatar

15 30 50 per page