- 考察素数判断
- 考察进制转换
import java.io.IOException; import java.io.InputStreamReader; import java.io.StreamTokenizer; public class Main { @SuppressWarnings("uncheck") public static void main(String[] args) throws IOException { StreamTokenizer st = new StreamTokenizer(new InputStreamReader(System.in)); int n, d; while (true) { st.nextToken(); n = (int) st.nval; if (n < 0) { break; } st.nextToken(); d = (int) st.nval; String str = Integer.toString(n, d); String reversestr = new StringBuilder(str).reverse().toString(); int p2 = Integer.parseInt(reversestr, d); if( isPrime(n) && isPrime(p2)){ System.out.println("Yes"); }else{ System.out.println("No"); } } } public static boolean isPrime(int n) { if (n == 1) { return false; } for (int i = 2; i <= Math.sqrt(n); i++) { if (n % i == 0) { return false; } } return true; } }
标签:StreamTokenizer,PAT,java,int,System,st,io,1015,Primes From: https://www.cnblogs.com/fishcanfly/p/17794771.html