5 kyu
Multiples of some primes
22 of 104koba1996
Loading description...
Mathematics
Algorithms
Performance
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
What's mean for Python? Time: 10865ms Passed: 10 Failed: 0 Exit Code: 137 and not about buffer or stderr or etc. But kata is not marked as solved. What should I do?
JavaScript translation
can there be problem after 16th or 17th digits? i dont understand??!! Anyone help?
It's just how you calculate your sum.
Fraction
is too inefficient. Get rid of it and your solution passes.Edit: Ok, reading Discord indeed floating point calculation were your prior problem, since they can store up to 16 digits exactly.
I just did, and it passed!! What a great Kata!! Suffered, but learned a bit, And asusual, some Awesome code are already in the solution page, some i understand, and some i don't. Alhamdulillah!! Thanks You Madjosz!!!
This is definitely not 5kyu, doesn't matter how I do it, always timeout in th big. Maybe there are some mathematical concepts that need to be taken into consideration? Any clue? :)
Creating a O(1) complexity solution for one prime is not very hard. Once you have that, I would recommend to learn about the inclusion-exclusion principle of combinatorics.
I did exactly that, O(1) for one prime and using inclusion-exclusion means that I have to do that binom(n, k) times for 1 <= k <= n. I pass 6 out of 6 30 digits tests but then my code times out. Am I still missing something?
This problem is way more strictly mathematical in fact and requires some generalization based on research indeed.
Any performance suggestions? I'm failing on the large test sets.
Once you created a O(1) solution for the cases where you have 2 primes in your input array, you might wanna read about the Inclusion-exclusion principle of combinatorics.
Awesome, thank you. I'll take a look now!
"I think this task is more about logic than performance, but I still recommend you to optimalize your code"
my logic is sound and works for the small/medium tests but it times out before it complete the large test. Not sure how to optimize the code to avoid the timeout issue though...
"I think this task is more about logic than performance, but I still recommend you to optimalize your code", hahahhah funny.
Its not 5kyu at all, i think its 4 or 3.
This comment has been hidden.
timed out ......
for i in range(1, number_limit)
You realize thatnumber_limit
is a number with 30 digits? Even if one iteration takes 1 nano second your program will run for 15 trillion years. :DPython translation
Thank you for your work!
This comment has been hidden.
I changed the access modifier
Random tests:
Arrays of prime numbers can be empty.
The following code
can be changed to
Remove
System.out.println(numberOfPrimes);
from the test code.This comment has been hidden.
I suggest to change
Integer[] primes
toint[] primes
everywhere. And don't forget to republish the kata when the issues below are fixed.That's a nice idea, I applied it!
Please update the initial solution and sample tests also. They still have
Integer[]
.Thanks, I updated it, and the example test cases as well.
Random tests are not sufficiently strong:
numberLimit
should be generated with the existingBigInteger
constructor.Thank you for the suggestion, I rewrote the random tests with random arrays and the constructor you suggested.
"a string containing a positive, whole number"
Random tests may generate negative numbers.
Nice catch, it was indeed a possibility. The method got removed.
This comment has been hidden.
Thank you for your insight, you are absolutely right! I just added a hundred random tests, that should prevent the hardcoded solutions.