Least common multiple of a list of numbers

I’m trying to learn computer science by doing some challenges. One is the following.

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

Let’s generalize the problem from $ 1$ to $ n$ .

I thought of a loop between $ n$ and $ n/2$ as everything above $ n/2$ is a multiple of something between $ 1$ and $ n/2$ . At each iteration, the result is the least common multiple of the loop variable and the precedent result (at the beginning the result is 1).

If I am correct, the complexity of this should be $ \mathcal{O}(n/2)$ . Am I right?

Is there any more efficient algorithms to solve this problem? If so witch one and what is their complexity?

Variant of the Strong Law of Large Numbers

Let $ X_1,X_2,\ldots$ be a i.i.d. sequence of random variables with uniform distribution on $ [0,1]$ , with $ X_n: \Omega \to \mathbf{R}$ for each $ n$ .

Question. Is it true that $ $ \mathrm{Pr}\left(\left\{\omega \in \Omega: \lim_{n\to \infty}\frac{\sum_{1\le i\neq j \le n}{\bf{1}}_{(-1/n,1/n)}{(X_i(\omega)-X_j(\omega))}}{n}=2\right\}\right)=1\,\,\,? $ $

Here $ {\bf{1}}_A(z)$ is the characteristic function of $ A$ , that is, it is $ 1$ if $ z \in A$ and $ 0$ otherwise.

What kind of numbers are inside a generating open interval of the Borel $\sigma$-algebra?

If it is enough to have all open intervals (a,b) with end points $ a$ and $ b$ belonging to the rational numbers, a < b, in order to generate a Borel $ \sigma$ -algebra on $ \mathbb{R}$ . Asked here: About the open intervals generating a Borel $ \sigma$ -algebra on $ \mathbb{R}$

What kind of numbers do you need to have between $ a$ and $ b$ ? Only rational numbers or real numbers? And why?

programatically edit numbers from messages

Here is the issue

i changed phones..

i before hand backed up calls and messages using sms backup and restore. everything went fine. I have the xml files i can see the messages and the numbers correctly in the xml.

the restore in the new phone for some reason decided to add the sim country code to every number that did not have a country code which made the numbers completely unusable I do not understand from where come the country code I do not see anywhere the settings in the aosp messaging app to remove the country code.

is there a way to edit the numbers on the messages or to make sms backup and restore app not to add the country code of the sim card.. I think it detects the country of the sim or the country of the phone based on imei? and then if a phone does not start by +xxx it add it..

I find totally unacceptable that the restore got somehow altered. and I cannot find the root cause..

questions is can i use adb or some api in python or whatever to fix the mistakes.. I still have the original xml files from sms backup and restore with the numbers untouched.

thank you

If a,b are amicable numbers show that $\left(\sum_{d|a}\frac{1}{d}\right)^{-1} + \left(\sum_{d|b}\frac{1}{d}\right)^{-1}=1$

Amicable numbers are the ones that the sum of the propers divisor of one of them is other and viceversa.

This is problem 8.4.51 from Elementary Number Theory from Koshy.

I have that we end with $ $ \left(\sum_{d|a}\frac{1}{d}\right)^{-1} + \left(\sum_{d|a}\frac{1}{d}\right)^{-1}=\left( \frac{\prod_{d|b} d}{a+b}\right) + \left(\frac{\prod_{d|a} d}{a+b}\right) $ $

So for the equality to hold we need that $ a,b$ be primes and considering that 220, 284 are the smallest amicables numbers so I press [x] to doubt.

So I guess the author mean proper divisors but I guess the editor omited that fact.

So then we have $ $ \left(\sum_{d|a}\frac{1}{d}\right)^{-1} + \left(\sum_{d|a}\frac{1}{d}\right)^{-1}=\left( \frac{\prod_{d|b} d}{b}\right) + \left(\frac{\prod_{d|a} d}{a}\right) $ $ therefore: $ $ \left(a \prod_{d|b} d\right)+\left(b \prod_{d|a} d\right) =1 $ $ However I fail to see why. Could you guys help me.

Find indices of two numbers such that they add up to a target

The task

…is taken from leetcode

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

Example:

Given nums = [2, 7, 11, 15], target = 9,

Because nums[0] + nums1 = 2 + 7 = 9, return [0, 1].

const lst = [11, 7, 15, 2] const target = 9; 

My imperative solution

function findIndexOfSumPair(lst, trgt) {   const len = lst.length;   for (let i = 0; i < len; i++) {     const found = lst.findIndex(x => trgt - lst[i] === x);     if (found !== i && found !== -1) {       return [found, i];     }   } }  console.log(findIndexOfSumPair(lst, target)); 

My functional solution

const findIndexOfSumPair2 = (lst, trgt) => {   return lst.reduce((res, x, i) => {     const j = lst.findIndex(y => target - x === y);     return j !== -1 ? [i, j] : res;   }); };  console.log(findIndexOfSumPair2(lst, target)); 

The disadvantage with my functional solution is that reduce iterates till the end of the array – even though it may have found a solution already. I tried to come up with a functional that stops iterating once it found a solution. I could come up with this. However it is too verbose and relies on side-effects (which doesn’t make it functional anymore):

const findIndexOfSumPair3 = (lst, trgt) => {   let res;    lst.some((x, i) => -1 !== lst.findIndex((y, j) => {     if (i !== j && trgt - y === x) {       res = [j, i];       return true;     }   }));   return res; };  console.log(findIndexOfSumPair3(lst, target)); 

Do you know an elegant and efficient functional solution?

Check which numbers satisfy the condition [A*B*C = A! + B! + C!]

#include <iostream> #include <cmath> using namespace std; int s = 1; //Serial No. 

Should I use recursion for the factorials function?

int Factorial(int n) {     int k=1;     for(int i=1;i<=n;++i)     {         k=k*i;     }     return k; } 

How I can go about doing this in a single for loop instead of the 3 while loops?

int main() {     int a = 1;     int b = 1;     int c = 1;     int Fact1;     int Fact2;     int Fact3;     while (a < 11)     {         Fact1 = Factorial(a);         while (b < 11)         {             Fact2 = Factorial(b);             while (c < 11)             {                 Fact3 = Factorial(c);                 cout << s << " : ";                 int LHS = Fact1 + Fact2 + Fact3;                 if (LHS == a * b * c)                 {                     cout << "Pass:" <<"    "<< a << " & " << b << " & " << c << endl;                 }                 else                 {                     cout << "Fail" /*<<"   "<< Fact1 <<"   "<< Fact2 <<"   "<<Fact3*/<<endl;                 }                     c++;                     s++;             }             c = 1;             b++;         }         b = 1;         a++;     }     return 0; } 

Also I would love some variable naming tips.

Proof of Weak Law of Large Numbers


For a sequence of i.i.d. random variable $ (X_n)$ with $ \Bbb{E}X=m$ , $ \overline{X}_n=(X_1+…+X_n)/n$ , then $ \overline{X}_n\stackrel{P}{\rightarrow}m$ .

Since $ (X_n)$ are i.i.d., $ (X_n)$ induce the same probability measure $ \mu$ on $ \Bbb{R}$ . So $ $ \Bbb{P}\{|\overline{X}_n-m|>\epsilon\}=\int_{\{|\frac{x_1+…+x_n}{n}-m|>\epsilon\}}\Bbb{1}(\mathrm{d}\mu)^n$ $ where $ (\mathrm{d}\mu)^n$ is the product measure of $ \mu$ . I want to know if we can prove weak law of large numbers by this representation. Any help will be appreciated.