+ 39
[ ASSIGNMENT: ] The Sum Of Prime Distance
We define the Prime Distance between two even numbers as : 》The number of primes between two even numbers!《 TASK : Given an integer array. Calculate the sum of the Prime Distance of each pair of elements in the array. NOTE! All elements in the array are unique even numbers and they are arranged in ascending order! Example : For arr = [ 4, 6, 12 ] the output should be 6 prime distance of (4, 6) --> 1 prime distance of (6,12) --> 2 prime distance of (4,12) --> 3 https://code.sololearn.com/W60Cek9HX6lW/?ref=app
34 Respuestas
+ 11
The number 2 is excluded as prime number for the following reason :
Task requirement is to Calculate the Sum of the 》Prime Distance《 of Each Pair of Elements in the Array?
Numbers 2 and 4 are pairs, and the distance between them is one prime number 3.
Numbers 2 and 6 are pairs, and the distance between them is two primers of numbers 3 and 5, for this reason :
prime distance of (2, 6) --> 2
Example :
Input array = [ 2, 6, 12 ], output should be 8.
prime distance of (2, 6) --> 2
prime distance of (6, 12) --> 2
prime distance of (2, 12) --> 4
--> 2 + 2 + 4 = 8
See the examples given in the assignment,
I hope it's clear now!
+ 25
+ 24
too hard danijel but i solve it
and awssoomm challange
https://code.sololearn.com/cj7AJVvHDvMV/?ref=app
+ 18
Kinshuk Vasisht don't worry 👍😉
HappyCodings!:-) 😄
&&
Have a nice day! 😃😆
+ 17
Nice challenge 👍
Here's my try (works up to 2.800.000) :
https://code.sololearn.com/cSYme5E8x2Ra/?ref=app
+ 17
Kinshuk Vasisht
Find the Sum of Prime Distance!
// 5, 13 are prime numbers
your example :
For input : arr = [ 4, 6, 14 ]
the output should be --> 8
prime distance of (4, 6) --> 1
prime distance of (6,14) --> 3
prime distance of (4,14) --> 4
--> 1 + 3 + 4 = 8
NOTE!
All elements in the array are unique Even numbers and they are arranged in Ascending order!
Please, can you see examples in the assignment!
+ 16
Manuel Soto
Please, this is an Assignment and we need to set the Solution for the Task!👍
Try to do it 😊 and then place your Code here 👌
Thank you, but there are different and better ways to share assignments!
//I believe, this is beginners mistake!👍😉
Welcome to SoloLearn! 🤗
HappyCodings!:-)
+ 16
~ swim ~
You're right, number 2 is the smallest prime number and that's true, but in the task it is required that the input array is consisted of only even numbers (number 2 is also the smallest even number), and because of this reason, I think number 2 is exclusive as prime number!
Number 2 is the only prime number that is even!
Honestly, I was struggling with the same question and thank you for your suggestion and drawing attention!
+ 16
~ swim ~
Thank you very much for this answer, 👏👏 😊
I know what math says and that's why I had problems with the task!
I really appreciate your efforts, 👍😉
and it's easier to work when the task is clear! 👌
I will leave the task with this setting, we will not change anything now! 👍
+ 15
Kinshuk Vasisht
do not disturb me, not to worry, ask me freely what you need, 😉
Please forgive me that I can not answer immediately because I am working 👍
for this example,
input : arr = [ 2, 6 ]
the output should be 2
The Prime Distance between 2 and 6 is 2, because there are two primes
between 2 and 6 --> (3, 5).
+ 15
~ swim ~
Ok, then we have to take the zero as an even number, because it is not assumed that zero belongs to a set of natural numbers!
It then changes the task in full!
Thank you very much for your suggestions! 👍
+ 14
Kinshuk Vasisht
you can freely write in the code specified in the assignment as an explanation of the task! 👍
+ 13
Thank you all, for providing support and suggesting that we do the task better,
I know that there will be problems and uncertainties related to the task and I'm trying the best I can to make the task clear,
but I have only the text of the task, and that's why every help is welcome, 👍
Thank you all for everything! 😊
+ 7
+ 6
It should be also an efficient approach:
https://code.sololearn.com/cYVK79L2POhZ/?ref=app
+ 5
Nice Challenge!
https://code.sololearn.com/cDHb3jqx8U6Y/#py
+ 5
Efficient solution (see example 23,56,20000,5000,1000000 including numbers up to 1 000 000)
Louis example of where prime explosion helps
https://code.sololearn.com/c327aHhsb69p/?ref=app
+ 4
Sorry, but yours are not really efficient for large array
like [i*2+4 for i in range(20000)]
Here is mine
https://code.sololearn.com/cjYUO1esy0L9/?ref=app
+ 4