I want to solve the infinitive equation of the reciprocal sum.

Asked 1 years ago, Updated 1 years ago, 278 views

I am using Google Collaboration.

The sum of reciprocals of different natural numbers is 1
1/x_1+1/x_2+‥‥+1/x_n=1(x_1>x_2>‥‥>x_n)
I would like to find out the number of sets (x_1 to x_n) for each value of the natural number n and the x for each set.

I've looked into various things, but maybe it's because of the reciprocal, I get only errors.
I would like you to give me an example code.

code.

Also, I introduced different x as a,b...,z, but is it possible to write well like (x_1>x_2>‥‥>x_n) as above?

There were no errors, but all solutions are not required

for i in range(2,999): 
 for jin range (i+1,999):
  forkin range (j+1,999):
   for line range (k+1,999):
     for min range (l + 1,999):
      if1/i+1/j+1/k+1/l+1/m==1:
       print(i,j,k,l,m)

Displays invalid syntax.

import sympy as sym
from sympy.abc import a, b, c, d, e, n 
from sympy.solvers.diophantine import diophantine
  
f=sym.Eq (a**-1+b**-1+c**-1+d**-1+e**-1,n)
diophantine(f.subs(n,1))

python google-columnatory

2022-11-09 23:12

1 Answers

https://docs.python.org/ja/3/library/fractions.html
Python has a rational number class from the beginning, so
If you use this, you can calculate accurately without worrying about errors.

import sys
from effects import Fraction

results = [ ]

# Fix up to fix_index in x_list and search by changing the remaining variables
# rest_value is the total value that can be used in terms that have not yet been determined
define(x_list, fix_index, rest_value):
    if fix_index>=len(x_list): # All variables determined
        ifrest_value==0:#1 exactly matched
            results.append(x_list[:])# Copy and add to results to avoid side effects
        return

    # Search ends if the remaining value is already negative
    if rest_value<=0:
        return

    # determine and explore the following
    # x_list assumes x1<=x2<=...<=xn (because I don't know the maximum value, so I want to increase it gradually starting with 2)
    # Fixed e.g.x1 x2 | x3 x4 x5 to find x3 can take x3 > = x2 and 1/x3 + 1/x3 + 1/x3 > = maximum x3 with rest_value
    # Because if x3 exceeds this, 1/x3+1/x4+1/x5 for x4x5 larger than x3 will not be enough to make the rest_value.
    # That is, the reciprocal of x3<(rest_value/number of undetermined variables)
    for x in range(x_list[fix_index-1] if fix_index else2, int(len(x_list)-fix_index)/rest_value)+1):
        # Determine x3 and search for the rest again
        x_list [fix_index] = x
        iter(x_list, fix_index+1, rest_value-Fraction(1,x))


defmain():
    n=int(sys.argv[1])
    x_list = [0]*n;
    iter(x_list,0,Fraction(1))#Search for a total of 1 without fixing at first
    print(results)


if__name__=='__main__':
    main()

Run Results

python test.py 5
[[2, 3, 7, 43, 1806], [2, 3, 7, 44, 924], [2, 3, 7, 45, 630], [2, 3, 7, 46, 483], [2, 3, 7, 48, 336], [2, 3, 7, 49, 294], [2, 3, 7, 51, 238], [2, 3, 7, 54, 189], [2, 3, 7, 56, 168], [2, 3, 7, 60, 140], [2, 3, 7, 63, 126], [2, 3, 7, 70, 105], [2, 3, 7, 78, 91], [2, 3, 7, 84, 84], [2, 3, 8, 25, 600], [2, 3, 8, 26, 312], [2, 3, 8, 27, 216], [2, 3, 8, 28, 168], [2, 3, 8, 30, 120], [2, 3, 8, 32, 96], [2, 3, 8, 33, 88], [2, 3, 8, 36, 72], [2, 3, 8, 40, 60], [2, 3, 8, 42, 56], [2, 3, 8, 48, 48], [2, 3, 9, 19, 342], [2, 3, 9, 20, 180], [2, 3, 9, 21, 126], [2, 3, 9, 22, 99], [2, 3, 9, 24, 72], [2, 3, 9, 27, 54], [2, 3, 9, 30, 45], [2, 3, 9, 36, 36], [2, 3, 10, 16, 240], [2, 3, 10, 18, 90], [2, 3, 10, 20, 60], [2, 3, 10, 24, 40], [2, 3, 10, 30, 30], [2, 3, 11, 14, 231], [2, 3, 11, 15, 110], [2, 3, 11, 22, 33], [2, 3, 12, 13, 156], [2, 3, 12, 14, 84], [2, 3, 12, 15, 60], [2, 3, 12, 16, 48], [2, 3, 12, 18, 36], [2, 3, 12, 20, 30], [2, 3, 12, 21, 28], [2, 3, 12, 24, 24], [2, 3, 13, 13, 78], [2, 3, 14, 14, 42], [2, 3, 14, 15, 35], [2, 3, 14, 21, 21], [2, 3, 15, 15, 30], [2, 3, 15, 20, 20], [2, 3, 16, 16, 24], [2, 3, 18, 18, 18], [2, 4, 5, 21, 420], [2, 4, 5, 22, 220], [2, 4, 5, 24, 120], [2, 4, 5, 25, 100], [2, 4, 5, 28, 70], [2, 4, 5, 30, 60], [2, 4, 5, 36, 45], [2, 4, 5, 40, 40], [2, 4, 6, 13, 156], [2, 4, 6, 14, 84], [2, 4, 6, 15, 60], [2, 4, 6, 16, 48], [2, 4, 6, 18, 36], [2, 4, 6, 20, 30], [2, 4, 6, 21, 28], [2, 4, 6, 24, 24], [2, 4, 7, 10, 140], [2, 4, 7, 12, 42], [2, 4, 7, 14, 28], [2, 4, 8, 9, 72], [2, 4, 8, 10, 40], [2, 4, 8, 12, 24], [2, 4, 8, 16, 16], [2, 4, 9, 9, 36], [2, 4, 9, 12, 18], [2, 4, 10, 10, 20], [2, 4, 10, 12, 15], [2, 4, 12, 12, 12], [2, 5, 5, 11, 110], [2, 5, 5, 12, 60], [2, 5, 5, 14, 35], [2, 5, 5, 15, 30], [2, 5, 5, 20, 20], [2, 5, 6, 8, 120], [2, 5, 6, 9, 45], [2, 5, 6, 10, 30], [2, 5, 6, 12, 20], [2, 5, 6, 15, 15], [2, 5, 7, 7, 70], [2, 5, 8, 8, 20], [2, 5, 10, 10, 10], [2, 6, 6, 7, 42], [2, 6, 6, 8, 24], [2, 6, 6, 9, 18], [2, 6, 6, 10, 15], [2, 6, 6, 12, 12], [2, 6, 7, 7, 21], [2, 6, 8, 8, 12], [2, 6, 9, 9, 9], [2, 7, 7, 7, 14], [2, 8, 8, 8, 8], [3, 3, 4, 13, 156], [3, 3, 4, 14, 84], [3, 3, 4, 15, 60], [3, 3, 4, 16, 48], [3, 3, 4, 18, 36], [3, 3, 4, 20, 30], [3, 3, 4, 21, 28], [3, 3, 4, 24, 24], [3, 3, 5, 8, 120], [3, 3, 5, 9, 45], [3, 3, 5, 10, 30], [3, 3, 5, 12, 20], [3, 3, 5, 15, 15], [3, 3, 6, 7, 42], [3, 3, 6, 8, 24], [3, 3, 6, 9, 18], [3, 3, 6, 10, 15], [3, 3, 6, 12, 12], [3, 3, 7, 7, 21], [3, 3, 8, 8, 12], [3, 3, 9, 9, 9], [3, 4, 4, 7, 42], [3, 4, 4, 8, 24], [3, 4, 4, 9, 18], [3, 4, 4, 10, 15], [3, 4, 4, 12, 12], [3, 4, 5, 5, 60], [3, 4, 5, 6, 20], [3, 4, 6, 6, 12], [3, 4, 6, 8, 8], [3, 5, 5, 5, 15], [3, 5, 5, 6, 10], [3, 6, 6, 6, 6], [4, 4, 4, 5, 20], [4, 4, 4, 6, 12], [4, 4, 4, 8, 8], [4, 4, 5, 5, 10], [4, 4, 6, 6, 6], [5, 5, 5, 5, 5]]


2022-11-09 23:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.