A.Santa Claus and a Place in a Class
A number is "prime" if it has no divisors other than itself and 1. For example, 23 is prime but 35 is not prime because 35 = 7 x 5. If the digits of a number are rearranged, then usually its primeness changes — for example, 35 is not prime but 53 is. For this problem, you must find numbers which are prime no matter how you rearrange their digits. For example, all of the numbers 113, 131 and 311 are prime, so we say that 113 is an "anagrammatic prime" (also 131 and 311 are anagrammatic primes).
Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the sbegin and ending with the send (it is possible sbegin = send), the given string t has. Substrings are different if and only if their contents aren't equal, their positions of occurence don't matter. Petya wasn't quite good at math, that's why he couldn't count this number. Help him!
C题是因为我没能考虑到特殊情况而苦于wa on 14,7 times