Can you please help me find an error in the code | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

Can you please help me find an error in the code

Write a program that searches among integers belonging to the numeric interval [321654; 654321] for numbers that have only odd divisors greater than 70. The divisors of 1 and the number itself are not considered. For each number found, write down the number itself and the maximal greatest divisor. Answer 405405 135135 530145 176715 592515 197505 626535 208845 My code def ch(x): l=set() for i in range (2, round(x**0.5)+1): if x%i==0: l.add(i) if all(int(c)%2 for c in l) and len(l)>70: return l return 0 for i in range (321654, 654321+1): if ch(i)!=0: print(i, max(l))

19th Sep 2023, 4:34 PM
Ariadna
11 Respuestas
+ 4
Ariadna , since `error` can be anything, please give a clear description what the issue is.
19th Sep 2023, 6:04 PM
Lothar
Lothar - avatar
+ 4
Ariadna , can you help me understand the task description: > we are searching for numbers that have only odd divisors and > and these divisors should also be greater than 70 the first number (solution) that you present in your post is: > 405405 > this number has divisors like 7, 9, 13, ... they are not greater than 70. can you please explain this?
19th Sep 2023, 7:35 PM
Lothar
Lothar - avatar
+ 4
Uday veer Boddh , please do not spam in the post of someone else. your supplied attachment has no relation to the question from the op.
21st Sep 2023, 4:00 PM
Lothar
Lothar - avatar
+ 4
RAGNAR , have you compared the output of your code with the mentioned output from the op?
21st Sep 2023, 4:02 PM
Lothar
Lothar - avatar
+ 3
Ariadna , thanks for giving this information, this sounds a bit different to me than the first description.
20th Sep 2023, 11:39 AM
Lothar
Lothar - avatar
+ 1
And the number of divisors must be greater than 70, we are not comparing each to 70
20th Sep 2023, 3:34 AM
Ariadna
+ 1
Try this : def check_criteria(n): max_divisor = 0 # We iterate until the square root of n for efficiency. for i in range(2, int(n**0.5) + 1): # If i divides n evenly, then it is a divisor. if n % i == 0: # Check the two potential divisors: i and n // i. for divisor in [i, n // i]: if divisor % 2 == 0 or divisor <= 70: return False, None # If a divisor is even or <= 70, return False. max_divisor = max(max_divisor, divisor) # Update the maximum divisor. return True, max_divisor results = [] for num in range(321654, 654321 + 1): valid, max_div = check_criteria(num) if valid: results.append((num, max_div)) for r in results: print(r)
21st Sep 2023, 9:16 AM
Ragnar The Nordman
Ragnar The Nordman - avatar
+ 1
Ragnar, your code doesn't match the condition a bit. For example, the number 654299. Its divisors are 73, 8,963. Total divisors: 2. 2<70 But the number 626535 has 78 divisors: 3, 5, 7, 9, 13, 15, 17, 21, 27, 35, 39, 45, 51, 63, 65, 81, 85, 91, 105, 117, 119, 135, 153... And since 78>70 , the program should output the number 626535
21st Sep 2023, 5:09 PM
Ariadna
0
You must include the maximum divisor in the answer
20th Sep 2023, 3:32 AM
Ariadna
21st Sep 2023, 3:42 PM
Uday veer Boddh
Uday veer Boddh - avatar
0
No relation ? Really ? Have a better look, please. I juste want to help not spamming ! No problem. I don't give help anymore.
21st Sep 2023, 4:22 PM
Ragnar The Nordman
Ragnar The Nordman - avatar