+ 8

[ASSIGNMENT] Betrothed numbers (quasi-amicable numbers)

Betrothed numbers are two positive integers such that the sum of the proper divisors of either number is one more than the value of the other number. The first few pairs of Betrothed numbers are: (48, 75), (140, 195), (1050, 1925), (1575, 1648), (2024, 2295), (5775, 6128). TASK 1: Check if two given by user numbers are Betrothed numbers. Input: 48 75 Output: True TASK 2: Print out all pairs of Betrothed numbers in a range from 1 to some limit given by user. Input: 200 Output: (48, 75), (140, 195)

23rd Apr 2018, 10:44 PM
Nevfy
24 Answers
+ 3
I thank everyone who participated in this challenge! Here is the list of all accepted solutions with their functionality: * print all 1-amicable (bertrothed) numbers from 1 to limit: - @Louis (Web) : https://code.sololearn.com/WvRowj9um83m/?ref=app * check if 2 numbers are n-amicable & print all n-amicable numbers from 1 to limit: - @VcC (Python) : https://code.sololearn.com/c3fdP9Yg2e5p/?ref=app - @~ swim ~ (C++) : https://code.sololearn.com/cp08T7nExl2D/?ref=app * check if 2 numbers are n-amicable & print all n-amicable numbers from 1 to limit & check for which n 2 numbers are n-amicable: - @LukArToDo (kt) : https://code.sololearn.com/c3aDBXjh2K5x/?ref=app - @Nevfy (Python) : https://code.sololearn.com/c5g3EKwh67KS/?ref=app
30th Apr 2018, 2:24 AM
Nevfy
+ 19
Nevfy 😀😄 it's a little tricky!! 👍😆
24th Apr 2018, 6:33 AM
Danijel Ivanović
Danijel Ivanović - avatar
27th Apr 2018, 4:22 AM
LukArToDo
LukArToDo - avatar
+ 14
Nevfy Thanks, I enjoyed it 😊 I'm really looking forward to your challenges because they push me think about my solution more than usual.
27th Apr 2018, 1:27 PM
LukArToDo
LukArToDo - avatar
24th Apr 2018, 6:57 AM
Louis
Louis - avatar
+ 6
EXTRA TASK: You can extend your code to perform for any two given numbers the following check: is there any number N such that the sum of the proper divisors of one number is more than the value of the other number by N and vice versa. And for given limit and N print out all pairs in a range from 1 to limit such that the sum of the proper divisors of either number is N more than the value of the other number. In such way, you code will be also a solution for Amicable Numbers (N=0) and Betrothed Numbers (N=1). Good luck!
23rd Apr 2018, 11:00 PM
Nevfy
24th Apr 2018, 11:24 AM
Emma
24th Apr 2018, 10:28 AM
VcC
VcC - avatar
+ 4
The definition of a betrothed number was ambiguous to me, so my code was therefore wrong: https://en.wikipedia.org/wiki/Betrothed_numbers When it says "EITHER number" in Wikipedia, it should say BOTH numbers. EITHER implies 'EITHER OR' to me.
24th Apr 2018, 10:48 AM
Emma
+ 4
Xan That is correct. It calculates all the Betrothed numbers up to the value entered try entering 3000 you should get 48 and 75 140 and 195 1050 and 1925 1575 and 1648 2024 and 2295
24th Apr 2018, 12:37 PM
Louis
Louis - avatar
+ 4
@VcC Agreed. I'm also missing some real THE challenges to solve. Maybe you can try to create one? :-) @Louis Maybe you can share yours? :-)
25th Apr 2018, 6:47 PM
Nevfy
+ 4
@LukArToDo Great! Finally someone have done fully the challenge including the extra task. Thank you and congratulations!
27th Apr 2018, 1:10 PM
Nevfy
+ 3
I found a 'bug' in python: This parses with no errors (note the bracket under the return) # Is this pair of numbers betrothed? def is_betrothed(x, y): return ( x > 0 and # Both numbers must be positive integers. y > 0 and (x % 2 != y % 2) and # Betrothed numbers are always opposite parity. ( (sum_of_divisors(x) == y + 1) and (sum_of_divisors(y) == x + 1) ) ) This works fine: # Is this pair of numbers betrothed? def is_betrothed(x, y): return ( x > 0 and # Both numbers must be positive integers. y > 0 and (x % 2 != y % 2) and # Betrothed numbers are always opposite parity. ( (sum_of_divisors(x) == y + 1) and (sum_of_divisors(y) == x + 1) ) ) This sent me off on a wild goose chase. It warns if a bracket is on the next line for an 'if' statement, but not a 'return' statement. Lol.
24th Apr 2018, 11:30 AM
Emma
+ 3
@~ swim ~ Very good! Thanks for participation! If you want, you can also add a code, which checks if it is possible for two input numbers to be a pair with some N or not.
27th Apr 2018, 11:27 PM
Nevfy
+ 3
Hey Nevfy This my try in Kotlin := Checked Upto 30000 in SoloLearn https://code.sololearn.com/cjxf5eqWbzz2/?ref=app
15th Jul 2018, 9:10 AM
Salman
Salman - avatar
+ 2
@louis When I click on 'Calculate' (after entering a single digit number) nothing happens. Is it working for you? Maybe something wrong my end. If I enter 99, and press Calculate, it says "48 and 75"
24th Apr 2018, 11:33 AM
Emma
+ 2
Betrothed numbers, are opposite parity for all known numbers (numbers below 10^10 at this time). It seems there's no formal proof for ALL numbers though. Number theory is like mining for gold ;-)
24th Apr 2018, 11:52 AM
Emma
+ 2
Well done Louis
24th Apr 2018, 12:57 PM
VcC
VcC - avatar
+ 2
Right! Apologies, I thought it was wanting two positive integers to check. Awesome code, and beautiful visually ☺ I've just noticed how large the text is explaining what to do. How could I miss that!? 😂😂
24th Apr 2018, 1:08 PM
Emma
+ 2
it seems that not obvious challenges get rarer and rarer... Making the interest in staying here lower for anybody mastering the basics - which i regret because the app and the community are great.
25th Apr 2018, 3:33 PM
VcC
VcC - avatar