math,greatest-common-divisor,lcm

I would calculate this in completely different way: the LCM of {1,...,n} is a product of all primes p[i]<=n, each in power floor(log(n)/log(p[i])). This product is divisible by all numbers up to n, and this is the least such number. Your main trouble is to calculate table of primes then.

You have two logical mistakes in your code 1) while 2) if (ca*cb / c == n){ Try the following code #include <iostream> #include <fstream> using namespace std; int main() { int a, b, c, ca, cb, i = 0, n; ifstream f("perechi.in"); ofstream g("perechi.out"); f >> n; for (a...

Have a look at the itertools.permutations function. Then it's simply merging the strings, parsing as int and multiplying them until you find the right one. Alternatively you can factorize N and then test if the pair of factors contains all the digits in S from itertools import permutations from numpy...

Trying all integer pairs in [1,n] is really overkill. You should factor n and count all products of the factors such that the required multiplicity is achieved by at least one of the products. (The lcm of two integers is the product of all their prime factors, each taken with...

You could convert it all to seconds and get the LCM. Use timedelta.total_seconds() https://docs.python.org/2/library/datetime.html...