PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SP0000173. Nguyên tố hoán vị chữ số (Anagrammatic Primes)
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ố hoán vị chữ số (Anagrammatic Primes)
Anagrammatic Primes
Phuoc Hung OJ ID: PRIME000178
Original source: UVa 897
Problem statement
An anagrammatic prime remains prime under every permutation of its digits. Given , find the next such prime without crossing the next power-of-ten boundary.
Input
One positive integer .
Output
Print the smallest anagrammatic prime with , where is the smallest power of ten greater than ; print 0 if none exists.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Example
Input
900
Output
919
Explanation: The distinct permutations of are , all prime, and it is the first qualifying number greater than .