Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Given an array a of N integers and Q queries where each query provides you with four integers L, R, X and Y.
you have to calculate value of each query according to the given function ?
F(L, R, X, Y) {

     result := 0
     for( i = X to i = Y )  {
         if( isPrime(i) ) {
             for( j = L to j = R ) {
                  number := a[j]
                  exponent := 0
                  while( number % i == 0 ) {
                     exponent := exponent + 1 
                     number := number/i
                  }
                  result := result + exponent
              }
         }
     }
     return result
}


isPrime(x) returns true if x is Prime otherwise false.

Example:
4 // size of array
2 3 4 5 // array elements
2 //number of queries
1 3 2 3 
1 4 2 5

Output:
4
5


What I have tried:

i have tried with pre computing all prime factors of all numbers in the array , but after that i have problem in processing queries
Posted
Updated 8-Jun-17 9:11am
v3
Comments
Richard MacCutchan 7-Jun-17 16:34pm    
Really? How interesting. Now, do you have a question?
Member 13244314 8-Jun-17 13:16pm    
i have edited my question , sorry for the problem
Richard MacCutchan 9-Jun-17 4:12am    
Well we still have no idea what problem you have.
Member 13244314 10-Jun-17 2:31am    
then you can never understand this question sorry
Richard MacCutchan 10-Jun-17 4:09am    
Well that's fine with me. If you do not want to explain your problem then do not be surprised if no one offers you a solution.

1 solution

Quote:
but after that i have problem in processing queries

This is the part that is the closest to a question, and you see we have nothing.

This is what you have to do in order to have hope for a solution.
- Choose the language.
- When you give example, give input, actual output and expected output.
- When you give code, give code complete enough to allow us to know what it does. Include calling code.
- "have problem", "not work" are not informative. Tell what it does and in what it is wrong.

For now, you are the only one able to help you.

There is a tool that allow you to see what your code is doing, its name is debugger. Mastering the debugger is not optional, it is mandatory for any programmer, no exception.
It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]
phpdbg | php debugger[^]
Debugging techniques for PHP programmers[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900