6
Challenge
In this task you would be given an integer N (less than 10^6), output the number of terms in the Farey sequence of order N.
The input N < 106 is given in a single line, the inputs are terminated by EOF.
The challenge is to implement the fastest solution so that it can process a maximum of 106-1 values as fast as possible.
Input
7
10
999
9999
79000
123000
Output
19
33
303793
30393487
1897046599
4598679951
Constraints
- You can use any language of your choice
- Take care about your fingers, do not use more than 4096 bytes of code.
- Fastest solution, based on the running time measured for N = 106-1.
Are you going to be timing each single submission in the same environment?! – J B – 2011-03-30T15:26:56.647
@J B:I guess the complexity only can do the trick,checking each submission in the same environment will probably give the same result. – Quixotic – 2011-03-30T15:29:15.600
1The complexity can be
O(1)
because the input size is limited so we can pre-compute a lookup table... – Peter Taylor – 2011-03-31T12:18:35.753@Peter Taylor:Thanks,for pointing that out,I have updated the constraints. – Quixotic – 2011-03-31T15:43:04.803