Untitled
unknown
plain_text
3 years ago
1.6 kB
6
Indexable
/* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template */ package sodep_3; /** * * @author tranh */ import java.util.*; public class SoDep_3 { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner cin = new Scanner(System.in); int t = cin.nextInt(); while (t-- > 0) { String s1 = cin.next(); //cin.nextLine(); if (isConvert(s1) & isPrimeString(s1)) { System.out.println("YES"); } else { System.out.println("NO"); } } } private static boolean isPrimeString(String s) { for (int i = 0; i < s.length(); i++) { if (!isPrime(Integer.parseInt(String.valueOf(s.charAt(i))))) { return false; } } return true; } private static boolean isPrime(int n) { if (n < 2) { return false; } for (int i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } private static boolean isConvert(String s1) { String s2 = ""; for (int i = 0; i < s1.length(); i++) { s2 += s1.charAt(i); } if (s1.equals(s2)) { return true; } return false; } }
Editor is loading...