Page 1 of 3
10990 - Another New Function
Posted: Sat Feb 11, 2006 8:37 pm
by jan_holmes
What method should we use in this problem ??? I use sieve... but still TLE...

How to make it faster ??? Thx...
Posted: Sat Feb 11, 2006 10:39 pm
by misof
How do you use the sieve, and what do you use it for? What is the time complexity of answering a single query in your solution?
If N is the largest possible input number, my solution precomputes data in O(N log N) and answers queries in O(1).
Posted: Sun Feb 12, 2006 4:46 am
by wook
Can I precompute all phi(1) to phi(N) values in O(N lgN) time?
Posted: Sun Feb 12, 2006 5:03 am
by Abednego
Yes, you can.
Posted: Sun Feb 12, 2006 7:52 am
by wook
hmm..
Anybody please, give me some hints for approaching computation of phi(1 to N) in order that its time-complexity may be O(n logn).
I can't easily find clear one!
Posted: Sun Feb 12, 2006 8:03 am
by Abednego
Do you know how to factor the numbers from 1 to N in O(NlogN) time? It's a simple modification to the standard Sieve of Erastosthenes. That's a start.
The next step is to look at the formula for phi(n) that uses the factorization of n.
Posted: Sun Feb 12, 2006 8:53 am
by wook
I got the picture by a simple modification of the sieve of Erastosthenes.
It is very simple idea, and now I finally knew how to do that.
Thank you very much, Abednego.
Posted: Sun Feb 12, 2006 10:27 am
by frankhuhu
Sorry,But could you tell me how to modify the sieve of Erastosthenes?
I try to modify it in order to get the factorization of n but get MLE.
So could you show me the picture? Thx!!
Posted: Sun Feb 12, 2006 10:40 am
by wook
The Memory complexity of modified-sieve-algorithm (for factorization of integers) should be O(N), not O(N lgN).
(I used just 4 arrays of size 2000000, and used memory is almost 30000.
You shouldn't use more than 4 linear-arrays, or you'll get MLE.)
for each integer v ∈ [1...N],
store the prime factor factor[v] that divides v.
And, another hint :
factorization of 72 can refer factorization of 9, if factor[72] is 2.
Posted: Sun Feb 12, 2006 11:34 am
by frankhuhu
I have made a silly mistake and get AC now!!
Andway thanks a lot !!

Posted: Mon Feb 13, 2006 3:40 pm
by polone
what should the test case be?
2
2 2000000
72 72
Posted: Mon Feb 13, 2006 4:09 pm
by misof
polone wrote:what should the test case be?
2
2 2000000
72 72
Output from my AC program:
Sample Input case plz.....
Posted: Mon Feb 13, 2006 6:02 pm
by greather
plz show me various sample input and output case ......
Posted: Mon Feb 13, 2006 7:24 pm
by lonelyone
sorry, but I want to know why I couldn't see the pictures in this problems?
could anyone tell me why.. appreciate ^^"
Posted: Mon Feb 13, 2006 7:34 pm
by Cho

There are some problems in the links to the images in UVa's problems occasionally. Or you can view the pdf files.