+ 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)
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
+ 19
Nevfy
😀😄 it's a little tricky!! 👍😆
+ 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.
+ 9
Did this a while back
https://code.sololearn.com/WvRowj9um83m/?ref=app
+ 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!
+ 6
Here's my code:
https://code.sololearn.com/cek0ktncWGr9/#py
+ 5
+ 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.
+ 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
+ 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? :-)
+ 4
@LukArToDo Great! Finally someone have done fully the challenge including the extra task. Thank you and congratulations!
+ 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.
+ 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.
+ 3
Hey Nevfy This my try in Kotlin :=
Checked Upto 30000 in SoloLearn
https://code.sololearn.com/cjxf5eqWbzz2/?ref=app
+ 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"
+ 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 ;-)
+ 2
Well done Louis
+ 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!? 😂😂
+ 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.