![TYUqnn2077](/avatars/25498.jpg)
TYUqnn2077
13.04.2021 •
Mathematics
Right now you are doing a complete search over the prefix sums. However, this is not necessary. We know that the only way to get a multiple of $7$ is if both prefix sums have the same remainder $\pmod{ 7}$. Then, what happens if there are a lot of these prefix sums with the same remainder. If they're located at indexes $a_1,a_2,a_3,... ,a_n$, your $O(n^2)$ solution is finding the maximum of all of the differences. But we don't need to check $a_2-a_1$, for example, since we know $a_n-a_1$ is divisible by $7$, and it must be larger. Thus, we only have to find $a_1$ and $a_n$, because all the other differences must be smaller. This means that for each remainder from $0$ to $6$, we can calculate $a_1$ and $a_n$, and find the maximum of their difference, which will be an $O(n)$ solution.
Solved
Show answers
More tips
- F Food and Cooking The Disease That Haunted Abraham Lincoln...
- P Philosophy What is Something for you?...
- S Style and Beauty Intimate Haircut: The Reasons, Popularity, and Risks...
- A Art and Culture When Will Eurovision 2011 Take Place?...
- S Style and Beauty How to Choose the Perfect Hair Straightener?...
- F Family and Home Why Having Pets at Home is Good for Your Health...
- H Health and Medicine How to perform artificial respiration?...
- H Health and Medicine 10 Tips for Avoiding Vitamin Deficiency...
- F Food and Cooking How to Properly Cook Buckwheat?...
- F Food and Cooking How Many Grams Are In a Tablespoon?...
Answers on questions: Mathematics
- M Mathematics Me i’m on my final and i need to pass...
- M Mathematics What is 183 million in scientific notation?...
- M Mathematics Neeed will give a lot of points for the answer...
- M Mathematics Tim has been trying to lose weight. through exercise, he was able to lose 5 pounds over 2 weeks. however, mary lost 10 times as much weight over 1 year of diet and...
- M Mathematics Here s a question that really stumps me and what is a scientific notation ? how would 3 times the number 0.000218107 be expressed in scientific notation? a. 65.4321...
- M Mathematics Point e is drawn on the graph so that line ef is parallel to line cd. if the coordinates of point e are (–4, y), what is the value of y?...
- M Mathematics The number of bacteria in a culture increases continuously and rapidly when put under a heat source. a culture containing 20 bacteria multiplies to 117,360 in one...
- M Mathematics In a crayon box there are 5 dark colors for every 8 light colors. if there are 20 dark colors, how many light colors are there?...
- M Mathematics Perform the indicated operation. Subtract (8x + 3) from (3x² + 2x + 7).(8x+3) subtracted from (3x² + 2x + 7) is...
- M Mathematics Please answer correctly...
Ответ:
you are too cute mhernbut alil smile will do it best