We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
A Weird Function
A Weird Function
Sort by
recency
|
8 Discussions
|
Please Login in order to post a comment
It seems to be OK to post code so let me share mine to show that you don't need lots of code to do it in Python
At first, find primes up to 2000000 with [linear seive of eratosten] .(https://cp-algorithms.com/algebra/prime-sieve-linear.html)
We have to compute Phi ( i ), if there is an integer j that j*(j+1)/2 = i . We know that i <= 10^12 . Though, j can be up to 2*10^6 . For finding Phi ( i ), if i = a*b which gcd(a,b)=1 , we can see that phi ( i ) = phi(a)phi(b) . We can do that for j(j+1)/2 . At last, we should make a prefix sum array with length of 2000000. For answering to each query, we have to know the largest i that i*(i+1)/2 <= R and the smallest j that j*(j+1)/2 >= L . The answer will be prefix [ i ] - prefix [ j-1 ].
C++ Solution :
I try to read and understand what you are offering.
เกมยิงปลา
thanks for sharing.
htc u11 case australia | iphone screen fix melbourne