Largest Prime Substring
Time limit1sMemory limit128 MB
Given a digit string, find the largest-valued contiguous substring that is prime and at most 100000.
- Level
Medium5 of 10
- Topics
- String, Brute force, Number theory, Prefix sum
- Solved
- No attempts yet
Problem
You are given a string consisting only of digits. Write a program that, among all contiguous substrings of the string interpreted as integers, finds the one that is prime and has the largest value.
In this problem, a number is considered prime only if it is a prime between and inclusive.
Input
The input consists of several test cases. The number of test cases does not exceed .
Each test case is given on its own line as a digit string whose length does not exceed . The last line of the input contains a single , which marks the end of the input.
Only inputs in which at least one substring is prime are given.
Output
For each test case, print on its own line the largest-valued prime substring.