The 2018 Egyptian Collegiate Programming Contest was held yesterday this was a problem from it where he asks for

Where n<=10^5 and a[i]<=10^5 answer should be printed %10^9+7

I would appreciate any help in solving this problem and thanks in advance

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

1 | tourist | 3372 |

2 | mnbvmar | 3345 |

3 | OO0OOO00O0OOO0O0…O | 3264 |

4 | Radewoosh | 3230 |

5 | scott_wu | 3189 |

6 | Benq | 3187 |

7 | LHiC | 3171 |

8 | Um_nik | 3155 |

9 | V--o_o--V | 3152 |

10 | Petr | 3139 |

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

1 | Radewoosh | 191 |

2 | Errichto | 172 |

3 | rng_58 | 159 |

4 | neal | 156 |

5 | Um_nik | 154 |

5 | tourist | 154 |

7 | Ashishgup | 151 |

7 | Petr | 151 |

7 | PikMike | 151 |

10 | 300iq | 150 |

The 2018 Egyptian Collegiate Programming Contest was held yesterday this was a problem from it where he asks for

Where n<=10^5 and a[i]<=10^5 answer should be printed %10^9+7

I would appreciate any help in solving this problem and thanks in advance

↑

↓

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Nov/17/2018 06:42:30 (f2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Auto comment: topic has been updated by Dijkstra. (previous revision, new revision, compare).hintinclusion exclusion

solution ideaFor a fixed

ghow many pairs that will have thisgas a gcd, it'll be all multiples ofg, it's easy to get the sum of multiplying those pairs.but there is a problem with this, there will be some pairs that will be calculated multiple times, so we have to exclude the answer of (2 *

g, 3 *g, ...), for example if we are solving wheng= 2 we know that all the numbers divisible by 4 is also divisible by 2, so we have to exclude the answer of 4, and so on.so the answer is iterate from the max number in descending order to 1 and solve for each fixed

g, the total complexity of this solution iscodeMhm... nice problem. Do you agree, mnbvmar?

<3

Story: We proposed this exact task (under a tiny bit different constraints, though) to our high school students back in 2015. I was quite surprised that apparently it has never appeared anywhere even though the statement feels really natural and obvious. So it seems it eventually did!

I think e-pluszak came up with another solution, involving...

Spoilerthe Möbius inversion formula

I can't remember any details, though. Mind sharing (if you still remember it)?

SolutionFirst I calculated an array

B[n] such, that (how: first set , then for eachifrom 1 toniterate over all multiples ofiand subtractB[i] fromB[di]).Now we can just iterate over all possible

dand add to accumulator sum of entries divisible bydsquared timesB[d]. This way for each paira[i],a[j] we have added , which is equal toThe only moment where Möbius inversion formula came into play was calculating

B[n] array. It can also be done using that formula, but the way I posted here is much easier. I think i used this approach on that contest back in 2015, but I'm not sure