PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SP0000062. Nguyên tố thứ n trong cấp số cộng (Dirichlet's Theorem on Arithmetic Progressions)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Nguyên tố thứ n trong cấp số cộng (Dirichlet's Theorem on Arithmetic Progressions)
Dirichlet's Theorem on Arithmetic Progressions
Source: Aizu Online Judge
Version: Phuoc Hung OJ Extended
Problem Statement
Given coprime positive integers , consider the infinite arithmetic progression . Keep only prime terms, preserving their original order. Given a positive integer , find the -th prime in this filtered sequence. Dirichlet’s theorem guarantees infinitely many such primes when ; the input guarantees the answer is less than .
Input
One line contains three positive integers , in that order.
Output
Print one integer: the -th prime in the given arithmetic progression.
Subtasks
- Subtask 1 (20 points): ; ; ; ; the answer is less than .
- Subtask 2 (30 points): ; ; ; ; the answer is less than .
- Subtask 3 (50 points): ; ; ; ; the answer is less than .
Examples
Input
2 3 3
Output
11
Explanation
The progression starts . Its prime terms are (first), (second), (third) and (fourth). Since , print the third prime, 11.