Problem Enumerating Rational Numbers

I don't know how to solve this problem, with the help of Euler's function. Can you explain me the idea for this problem?

# | User | Rating |
---|---|---|

1 | MiFaFaOvO | 3681 |

2 | tourist | 3673 |

3 | Um_nik | 3493 |

4 | apiadu | 3397 |

5 | 300iq | 3317 |

6 | maroonrk | 3250 |

7 | Benq | 3230 |

8 | LHiC | 3229 |

9 | TLE | 3223 |

10 | ecnerwala | 3216 |

# | User | Contrib. |
---|---|---|

1 | antontrygubO_o | 192 |

2 | Errichto | 185 |

3 | tourist | 182 |

4 | vovuh | 170 |

5 | pikmike | 168 |

6 | ko_osaga | 165 |

7 | Radewoosh | 164 |

8 | Um_nik | 162 |

9 | 300iq | 155 |

10 | Petr | 153 |

Problem Enumerating Rational Numbers

I don't know how to solve this problem, with the help of Euler's function. Can you explain me the idea for this problem?

↑

↓

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/08/2020 08:45:30 (g1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Ok, got accepted.

http://pastebin.com/2rFPsEHx

Ah, you cant calc euler function for 1...n on each test case, too expensive(n * sqrt(n)), precalc it :)

nin time, using this approach:Wow, thnks for that. But it seems like the complexity is O(n*log(log(n)))

Wow. That is a clever use of the Divisor Sum property of the Euler Totient Function.

I know this is an old comment haha, but shouldn't

`phi[1] = 1`

? Since gcd(0, 1) = 1?Yes. You should initialize $$$\phi(1)=1$$$ and start the bottom loop from $$$i = 2$$$.