코드비교

Old VersionNew Version
1import java.util.Scanner; 1import java.util.Scanner; 
2import java.lang.String;   
3public class Main { 2public class Main { 
4public static int rev(int num) { 4public static int Prime(int n) {
5int rev=0; 5for(int i = 2; i * i <= n; i++) {
6while(num != 0) { 6if((n % i) == 0) return 1;
7rev = 10*rev + num%10;   
8num /=10;   
9} 6} 
10return rev; 10return 0;
11} 8} 
12public static boolean check(int num) { 12public static int digit(int num) {
13int cnt=0; 13if(num == 0) return 0;
14for(int i=1; i<=num; i++) { 14else return digit(num / 10) + 1;
15if (num%i==0)  cnt++;   
16} 12} 
17if(cnt==2) return true; 13public static int ForPalendrome(int num, int digit) {
18else return false; 14int P = (int)Math.pow(10, digit - 1);
   15if(digit < 2) return 0;
   16else {
   17if((num / P) == (num % 10)) return ForPalendrome((num % P) / 10, digit - 2);
   18else return 1;
   19}
19} 20} 
20public static void main(String[] args) { 21public static void main(String[] args) { 
21Scanner sc = new Scanner(System.in); 22Scanner sc = new Scanner(System.in); 
22int rep = sc.nextInt(); 23int N = sc.nextInt();
23for(int i=0; i<rep; i++) { 24for(int i = 0; i < N; i++) {
24int max = sc.nextInt(); 25int count = 0;
25int cnt=0; 26int num = sc.nextInt();
26for(int j=1 ; j<=max ; j++) { 27for(int j = 2; j <= num; j++) {
27if(rev(j)==j) { 28if(Prime(j) == 0)
28if(check(j)) { 29if(ForPalendrome(j, digit(j)) == 0)
29cnt++; 30count++;
   31}
   32if(i < N - 1) System.out.println(count);
   33else System.out.print(count);
30} 34} 
31} 35} 
32} 36} 
33System.out.printf("%d\n", cnt);   
34}   
35}   
36}   
import java.util.Scanner;
import java.lang.String;
public class Main {
public static int rev(int num) {
int rev=0;
while(num != 0) {
rev = 10*rev + num%10;
num /=10;
}
return rev;
}
public static boolean check(int num) {
int cnt=0;
for(int i=1; i<=num; i++) {
if (num%i==0)   cnt++;
}
if(cnt==2)  return true;
else return false;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int rep = sc.nextInt();
for(int i=0; i<rep; i++) {
int max = sc.nextInt();
int cnt=0;
for(int j=1 ; j<=max ; j++) {
if(rev(j)==j) {
if(check(j)) {
cnt++;
}
}
}
System.out.printf("%d\n", cnt);
}
}
}
import java.util.Scanner;
public class Main {
public static int Prime(int n) {
for(int i = 2; i * i <= n; i++) {
if((n % i) == 0) return 1;
}
return 0;
}
public static int digit(int num) {
if(num == 0) return 0;
else return digit(num / 10) + 1;
}
public static int ForPalendrome(int num, int digit) {
int P = (int)Math.pow(10, digit - 1);
if(digit < 2) return 0;
else {
if((num / P) == (num % 10)) return ForPalendrome((num % P) / 10, digit - 2);
else return 1;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
for(int i = 0; i < N; i++) {
int count = 0;
int num = sc.nextInt();
for(int j = 2; j <= num; j++) {
if(Prime(j) == 0)
if(ForPalendrome(j, digit(j)) == 0)
count++;
}
if(i < N - 1) System.out.println(count);
else System.out.print(count);
}
}
}