PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000037. Vùng đất số nguyên tố (Prime Land)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Vùng đất số nguyên tố (Prime Land)

Prime Land

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

In Prime Land, an integer x>2x>2 is represented using pairs (p,e)(p,e), meaning prime pp occurs to exponent e>0e>0 in the factorization of xx. Only primes with positive exponents appear, in decreasing order of pp.

You are given the representation of xx. Subtract one and output the prime-power representation of x−1x-1, also with primes in decreasing order. For example, 5 1 2 1 means x=51⋅21=10x=5^1\cdot2^1=10, so x−1=9=32x-1=9=3^2.

Input

One line containing an even number of positive integers p1,e1,p2,e2,…,pk,ekp_1,e_1,p_2,e_2,\ldots,p_k,e_k. Each pip_i is prime and p1>p2>⋯>pkp_1>p_2>\cdots>p_k; ei≥1e_i\ge1. They represent x=∏pieix=\prod p_i^{e_i}.

Output

Print the prime-exponent pairs of x−1x-1 on one line separated by spaces, in decreasing prime order.

Subtasks

  • Subtask 1 (20 points): 3≤x≤1003\le x\le100; k≥1k\ge1; các pip_i là số nguyên tố đôi một phân biệt theo thứ tự giảm dần; ei≥1e_i\ge1; x=∏pieix=\prod p_i^{e_i}.
  • Subtask 2 (30 points): 3≤x≤1043\le x\le10^4; k≥1k\ge1; các pip_i là số nguyên tố đôi một phân biệt theo thứ tự giảm dần; ei≥1e_i\ge1; x=∏pieix=\prod p_i^{e_i}.
  • Subtask 3 (50 points): 3≤x≤327673\le x\le32767; k≥1k\ge1; các pip_i là số nguyên tố đôi một phân biệt theo thứ tự giảm dần; ei≥1e_i\ge1; x=∏pieix=\prod p_i^{e_i}.

Examples

Input

17 1

Output

2 4

Explanation

Input 17 1 represents x=171=17x=17^1=17. Then x−1=16=24x-1=16=2^4, so the output is 2 4.

Input

5 1 2 1

Output

3 2

Explanation

The input pairs represent x=51⋅21=10x=5^1\cdot2^1=10. Subtracting one gives 9=329=3^2, printed as 3 2.