PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000222. Đếm cặp sau khi chia cả hai số (Divide Both)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm cặp sau khi chia cả hai số (Divide Both)
Divide Both
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given , count ordered pairs with . Let . A pair qualifies iff , and . The order matters: and are distinct when . Exclude pairs in which one number divides the other.
Input
One line containing .
Output
Print the number of valid ordered pairs.
Subtasks
-
Subtask 1 (20 points): .
-
Subtask 2 (30 points): .
-
Subtask 3 (50 points): .
Examples
Example 1
Input
3 7
Output
2
Explanation
Exactly the two ordered pairs (4,6) and (6,4) qualify: their GCD is 2, and dividing both numbers by 2 yields 2 and 3.
Example 2
Input
4 10
Output
12
Explanation
Count ordered pairs with GCD greater than 1, then remove pairs in which either number divides the other. The answer is 12.