Fairy Lights
Time limit1sMemory limit128 MB
For each pressed button, compute the limiting fraction of integers whose final color is that button's color.
- Level
Medium6 of 10
- Topics
- Math, Number theory, Combinatorics, Prefix sum
- Solved
- No attempts yet
Problem
Little Johny has received a most unusual Christmas present. The label on the freshly unwrapped box read “Infinite chain of fairy lights”. Amused, the boy laid out his new toy on the floor.
Johny's chain is a cable with only one end: it begins at some point but never ends, stretching on forever. Fairy lights hang from the cable, numbered with consecutive natural numbers in the order they were attached, starting from . The cable is plugged into a control panel. The panel has several buttons, each with a unique colour and a unique positive integer written on it. The integers written on the buttons are pairwise relatively prime.
At first no light was on. Johny pressed every button one by one, from the first to the last. Pressing the -th button turns on exactly the lights whose numbers are multiples of (the integer on that button), and they shine in that button's colour . In particular, any light that was already on but whose number is a multiple of changes its colour to .
So the final colour of each light is the colour of the last-pressed button whose divides that light's number.
Let be the number of lights shining with colour among the lights numbered . The fraction of lights shining with colour is defined as:
Write a program that, for each colour , computes the fraction of lights shining with that colour.
Input
The first line contains a single integer (), the number of buttons on the control panel. Each of the next lines contains a single integer (), meaning that pressing the -th button makes the lights whose numbers are multiples of shine with colour . The values are given in exactly the order Johny pressed the buttons. The values are pairwise relatively prime (and therefore all different).
Output
Print exactly lines. The -th line must contain the fraction of lights shining with colour , written as a fraction where is an integer, is a positive integer, and and are relatively prime. If , print it as .