Christmas divisors

3.7

3 votes
Mathematics, Medium, Approved, Number Theory
Problem

Little Santa loves to play games on the Christmas Eve. He has invited N nice children from all over the world. Each child has a unique number from 1 to N. Among these N children, he will select only those children who have a divisor of N (including 1 and N).

Now he asked all the selected children to stand in a circle. Little Santa wants to have each pair of adjacent children to be a Good Pair. A Good Pair (a,b) is a pair in which either a divides b or b divides a.

enter image description here

All the children got confused and asked your help to place them.

Note: N=p1a1p2a2...pkak where p1,p2,...,pk are the prime factors of N.

Input format:
First line contains an integer, k (1k15), number of prime factors of N (2N1018). Next k lines contains two space separated integers each, pi and ai.

All pi are pairwise distinct primes, ai are positive integers.

Output format:
Print T space separated integers denoting the placement of children on the circle. T is the number of divisors of N. Print No if there is no solution.

Sample Input
2
2 1
3 1
Sample Output
1 2 6 3 
Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?