The Stack Overflow podcast is back! Listen to an interview with our new CEO.

# Questions tagged [mathematics]

For code that aims to solve problems in all branches of mathematics. (Please do NOT use this tag for incidental trivial use of arithmetic. A simple test to apply is: would an amateur or professional mathematician take an interest in the question?)

433 questions
Filter by
Sorted by
Tagged with
306 views

### Calculating a ton of mathematical constants

For a while now I have been working to construct a program to calculate a lot of mathematical constants. Before I explain, here's the code: Code ...
528 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 ...
89 views

### Improved Atkin-Bernstein sieve for generating primes

This is a class from my personal code library, and from a package which deals with integer sequences. It implements an interface ...
2k views

### Absolute Values and Fractions

$$\frac{|x|-|y|}{1+|xy|}$$ How can I reduce the amount of code without losing quality? What are your tips? Your comments on the structure, logic, in general, everything. How to make the type of ...
96 views

### Slow projection maths in C++ code

I'm optimising our codebase and currently, the slowest part of the code is a method called calculateResourceZ which is used in projections. I'm looking for ...
2k views

### Sum of proper divisors of every number up to N

I wrote a function which provides the sum of proper divisors of every number up-to N (N is a natural number) and I want to improve its performance. For example, if N = 10 then the output is: ...
2k views

### I finally solved the Birthday Problem using Java

I like to put ideas and mathematics into code whenever I am interested in the subject. Ever since I was introduced to The Birthday Problem I wanted to throw it into a Java program. I started writing ...
194 views

### Coq proof that type isomorphism relationship is transitive

The following code is in Coq, a proof assistant by INRIA implemented in OCaml. I'm defining two types as being isomorphic when there exists two functions ...
2k views

This is the question I am facing at level 3 of Google Foobar: There are two types: Mach bombs (M) and Facula bombs (F). The bombs, once released into the LAMBCHOP's inner workings, will ...
54 views

### Homework distribution terminal app in C++

I'm working on cleaning this code up a bit and was hoping for some suggestions. Right now it works well enough on a basic level, but it doesn't check for out of bounds numbers or improper input. ...
3k views

### Finding the greatest common factor of a list of numbers in JavaScript

The goal of this code is to take an array of two or more positive integers and return their greatest common factor, or GCF. (This is the biggest number that can be divided into all the numbers in the ...
162 views

### Find target sum of 3 from and array

Input is a sorted array and a target sum. Find all sets of 3 unique elements that sum to a target. Looking for lowest order (big O). A, B, C are the indexes on the sorted array. A < B < C ...
496 views

### C++ mathematical vector class

I plan to implement a simple simulation in C++, which requires mathematical vectors. The following header file contains the complete vector class with all it's method definitions. By overloading ...
740 views

### Searching for three positive integers as a solution to an equation

I recently ran into a question on M.SE asking, For positive integers x, y, z find a solution s.t. $\frac{x}{y+z} + \frac{y}{x+z} + \frac{z}{x+y} = 4$ so rather than think, I made a quick brute ...
5k views

### Count the number of ways an integer can be represented as a sum of consecutive positive integers

I am trying to count the number of ways an integer can be represented as sum of 2 or more consecutive positive integers. My Code is working in under 1 second for small inputs ($\le 10^7$) but after ...
331 views

### Optimizing special cases of modulo

I have a use case where improvements to the speed of calculating modulo for 64 bit integer dividends makes a significant difference in overall processing time. The divisor isn't known statically - it ...
144 views

### Golfed Inverse Ackermann Function [closed]

The following was posted on PPCG: Your job is to create the slowest growing function you can in no more than 100 bytes. I did some Googling, and I was interested in the Inverse Ackermann Function: ...
7k views

### Implementation of a Fraction class in Java

I am writing a bunch of Math related classes:BigInteger,Fraction,matrix,vector,polynomial,set etc.All of these classes will use each other.The classes will either work in decimal format or in Rational ...
334 views

### Convert a double to a string containing rational and surd

First off, code: ...
1k views

### Generating Uniformly Distributed Random Numbers

Edit: Dunno what PCG is and don't want to read the paper? Maybe this video of Melissa O'Neill (the author) explaining things will be palatable instead. Original: I attempted to answer this question ...
213 views

### Total number of common factors for two numbers LARGE VALUES up to 10^12

Inputs are two values $1 \le m , n \le 10^{12}$. I don't know why my code is taking so long for large values where the time limit is 1 sec. Please suggest some critical modifications. ...
1k views

### Inti Sets: Hackerank

Here is the original question. In order to motivate his Peruvian students, a teacher includes words in the Quechua language in his math class. Today, he defined a curious set for a given ...
2k views

### Decide whether a triangle is isosceles or not

I think I have pretty much the best code you can get when it comes to this particular task, but I'm always open to improvement. This code will check everything I can think of to make sure that it will ...
339 views

### Practical number algorithm

I am trying to write a program to find the practical numbers, from an input from $1$ to $n$. Practical numbers My code is running correctly but it is extremely slow when calculating numbers ...
1k views

### Image Compression Using the Singular Value Decomposition (SVD) with MATLAB

I'm new to both linear algebra and MATLAB. I need help with this code with the objective of compressing image using the Singular Value Decomposition (SVD). The code is currently working, if I run with ...
144 views

### Computing max t such that tanh(pi*sinh(t)/2) <1

I'm looking for a way to quickly determine that maximum value of t such that tanh(pi/2 sinh(t)) is strictly less than 1, for a ...
142 views

### 4 distinct integers, whose reciprocals sum up to 1

I wrote the following short python program to solve a math puzzle, which asked for all the 4-tuples of distinct natural numbers whose reciprocals sum up to 1. ...
201 views

### Resizing a discrete uniform CSRNG distribution

I have a requirement to generate a uniform distribution of cryptographically secure random numbers. To generate these numbers I only know of the ...
360 views

### Find highly composite number using Python 3

A highly composite number (HCN) is a positive integer with more divisors than any smaller positive integer ha according to Wikipedia. Here is a YouTube video about it. ...
54 views

### Finding the last ten digits of $\sum_{n=1}^{1000} n^n$
This is my solution to Project Euler Problem 48. Problem: The series, $1^1 + 2^2 + 3^3 + ... + 10^{10} = 10405071317$ . Find the last ten digits of the series, \\$1^1 + 2^2 + 3^3 + ... + ...