BlueTube Park
Time limit2sMemory limit1024 MB
For each A_i, find the smallest index j (j not equal to i) whose value is closest in prime-operation distance, where each multiply or divide by a prime counts as one step.
- Level
Hard8 of 10
- Topics
- Number theory, Hash map, Brute force
- Solved
- No attempts yet
Problem
Uncle Pasha likes to walk in the BlueTube park. Sometimes people get abducted by aliens during their walks. Unfortunately, this happened to our hero.
The aliens asked Pasha to solve a hard problem, whose optimal solution would help them conquer the world. The problem is as follows: you are given a list of natural numbers . The numbers are indexed from 1. For each , find the minimal () such that for every (, ).
is the minimal number of operations needed to turn into . In one operation, the aliens can multiply or divide a number by any prime. A prime is a number with exactly two distinct divisors, 1 and itself. For example, .
Input
The first line contains the number (), the number of values in the list.
Each of the next lines contains one value (), starting from .
Output
Print lines, one number per line. Line must contain the required index for .