PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000131. BCNN trên bảng (LCM on Whiteboard)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
BCNN trên bảng (LCM on Whiteboard)
LCM on Whiteboard
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are positive integers, each given by prime factorization , with strictly increasing primes within each number. Choose exactly one position and replace its number with 1. Count the distinct LCM values obtainable from all possible chosen positions.
Input
The first line contains . For each , read , followed by lines containing pairs .
Output
Print the number of distinct LCMs obtainable after one replacement.
Subtasks
- Subtask 1 (20 points): ; ; ; (nguyên tố, tăng nghiêm ngặt trong mỗi số); .
- Subtask 2 (30 points): ; ; ; (nguyên tố, tăng nghiêm ngặt trong mỗi số); .
- Subtask 3 (50 points): ; ; ; (nguyên tố, tăng nghiêm ngặt trong mỗi số); .
Examples
Input
2
1
2 2
1
3 1
Output
2
Explanation
Replacing with 1 leaves LCM 3; replacing 3 with 1 leaves LCM 4. These are distinct, hence the answer is 2.