Skip to main content

All Questions

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
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
3 votes
2 answers
588 views

Time limit exceeded on finding out the GCD and LCM of a Python list

I'm doing this HackerRank problem: Consider two sets of positive integers, \$A=\{a_0, a_1, \ldots, a_{n-1}\}\$ and \$B=\{b_0, b_1, \ldots, b_{m-1}\}\$. We say that a positive integer, \$x\$, is ...
Sidharth Samant's user avatar
4 votes
3 answers
303 views

Time Limit Exceeded for ETF - Euler Totient Function at Spoj

In number theory, the totient φ of a positive integer n is defined to be the number of positive integers less than or equal to n that are coprime to n. Given an integer n (1 ≤ n ≤ 106), compute the ...
sarvajeetsuman's user avatar
5 votes
6 answers
9k views

Counting pairs of relatively prime numbers

Problem from Hacker Earth: Inverted GCD: Given an array a of \$N\$ numbers , you have to find the number of pair of indices \$i\$ and \$j\$ that satisfy the following relation: \$i <...
Kaushal28's user avatar
  • 455
3 votes
1 answer
2k views

Project Euler #549: Divisibility of factorials

This is the problem: Calculate $$\sum_{i=2}^{10^8} s(i)$$ where \$s(n)\$ is the smallest \$m\$ such that \$n\$ divides \$m!\$. Quite mathematical, I've found a better way than brute ...
pjpj's user avatar
  • 131
6 votes
2 answers
409 views

Central Delannoy numbers

I am solving this problem on SPOJ Upper Right King (Hard): There is a king in the lower left corner of the \$ n \times n \$ chess board. The king can move one step right, one step up or one step up-...
rohspeed's user avatar