import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
//임의의 자연수를 받기 위한 변수
int num;
//시간복잡도를 잡기 위해서 이미 확인한 숫자들은 소수인지 아닌지 boolean으로 구분하며 해시맵에 담아둠
HashMap<Integer, Boolean> map = new HashMap<>();
//숫자를 받아오면서 바로 num에 담고, 담은 숫자가 0일 때까지 반복
while ((num = Integer.parseInt(br.readLine())) != 0) {
//출력용 숫자를 모을 변수
int result = 0;
//임의의 자연수 n보다 크고, 2n보다 작거나 같아야 하기 때문에 범위는 n+1 ~ 2n까지임
for (int i = num + 1; i <= 2 * num; i++) {
//만약 map에 숫자가 없으면
if (map.getOrDefault(i, null) == null) {
//소수인지 파악하기
boolean check = true;
for (int j = 2; j <= Math.sqrt(i); j++) {
if (i % j == 0) {
check = false;
break;
}
}
//check가 true이면 소수, false이면 소수가 아닌 숫자
//그대로 map에 넣고, result 값도 추가
map.put(i, check);
result += check ? 1 : 0;
} else { //만약 map에 있으면 map의 boolean에 따라 result 값 추가
result += map.get(i) ? 1 : 0;
}
}
bw.write(result + "\n");
}
bw.flush();
bw.close();
}
}
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
//체크용 boolean 배열
boolean[] list = new boolean[10001];
//1부터 10000까지 d() 함수로 보내고 체크하기
for (int i = 1; i <= 10000; i++) {
int num = d(i); //d함수 리턴값 : 정수
//만약 리턴값이 10000보다 작고, 만들어진 적 없는 숫자라면 true로 체크하기
if (num <= 10000 && !list[num]) list[num] = true;
}
//1부터 10000까지 방문 기록이 없는 숫자는 출력하기
for (int i = 1; i < list.length; i++) {
if (!list[i]) bw.write(i + "\n");
}
bw.flush();
bw.close();
}
public static int d(int num) {
int result = num;
while (num > 0) {
result += (num % 10);
num /= 10;
}
return result;
}
}
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String name = br.readLine();
int nameLength = name.length();
//연두 이름 기준 L, O, V, E 개수
int L = nameLength - name.replaceAll("L", "").length();
int O = nameLength - name.replaceAll("O", "").length();
int V = nameLength - name.replaceAll("V", "").length();
int E = nameLength - name.replaceAll("E", "").length();
//팀 개수
int t = Integer.parseInt(br.readLine());
//확률의 가장 작은 숫자 0과 팀 이름의 사전적으로 가장 마지막인 ZZZZZZZZZZZZZZZZZZZZ로 설정
int max = 0;
String result = "ZZZZZZZZZZZZZZZZZZZZ";
//팀 명 하나씩 꺼내면서 확률 측정하기
for (int i = 0; i < t; i++) {
String team = br.readLine();
int teamLength = team.length();
int tL = teamLength - team.replaceAll("L", "").length();
int tO = teamLength - team.replaceAll("O", "").length();
int tV = teamLength - team.replaceAll("V", "").length();
int tE = teamLength - team.replaceAll("E", "").length();
int total = sum(L+tL, O+tO, V+tV, E+tE);
if (max < total) {
max = total;
result = team;
} else if (max == total) {
if (result.compareTo(team) > 0) {
result = team;
}
}
}
System.out.println(result);
}
public static int sum(int l, int o, int v, int e) {
return ((l+o) * (l+v) * (l+e) * (o+v) * (o+e) * (v+e)) % 100;
}
}
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//주어진 숫자
int n = Integer.parseInt(br.readLine());
//왼쪽 숫자
int first = n / 10;
//오른쪽 숫자
int second = n % 10;
//리턴할 횟수
int result = 0;
//while문은 계속 반복하다가 조건에 맞으면 탈출할 수 있도록 true 넣기
while (true) {
//while문이 시작하자마자 바로 횟수 + 1
result++;
//왼쪽 숫자와 오른쪽 숫자를 더해서 새로운 숫자를 만들고
int create = first + second;
//왼쪽 숫자에는 오른쪽 숫자를 재할당
first = second;
//오른쪽 숫자에는 새로 만든 숫자의 1의 자리 숫자를 할당
second = create % 10;
//만약 왼쪽 숫자와 오른쪽 숫자가 처음 주어진 숫자와 동일하다면 break
if (first == n / 10 && second == n % 10) break;
}
System.out.println(result);
}
}
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
//입출력 객체들 선언
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
//가장 첫 번째 줄은 배열의 길이와 질문의 개수가 나옴
//띄어쓰기로 구분되어 있기 때문에
//읽어 들이면서 split()으로 구분
String[] nm = br.readLine().split(" ");
//첫 번째 줄 숫자로 변환
int n = Integer.parseInt(nm[0]);
int m = Integer.parseInt(nm[1]);
//배열 a 선언
int[] a = new int[n];
//입력 순서대로 정수로 변환하면서 배열 채우기
for (int i = 0; i < n; i++) {
a[i] = Integer.parseInt(br.readLine());
}
//퀵 정렬 호출
quick(a, 0, a.length-1);
for (int i = 0; i < m; i++) {
bw.write(check(Integer.parseInt(br.readLine()), a, 0, a.length-1) + "\n");
}
bw.flush();
bw.close();
}
public static int check(int num, int[] a, int start, int end) {
while (start+1 < end) {
int mid = (start + end) / 2;
if (a[mid] >= num) {
end = mid;
} else {
start = mid;
}
}
return a[start] == num ? start : a[end] == num ? end : -1;
}
//퀵 정렬 함수
public static void quick(int[] a, int start, int end) {
//cutting 함수 호출 - 리턴값 정수
int cut = cutting(a, start, end);
if (start < cut-1) quick(a, start, cut-1);
if (cut < end) quick(a, cut, end);
}
public static int cutting(int[] a, int start, int end) {
//중간 위치와 중간 위치의 값인 피벗 선언하기
int mid = (start + end) / 2;
int pivot = a[mid];
//start가 end보다 작거나 같을 때까지 반복
while (start <= end) {
//start위치의 값이 피벗보다 큰 경우까지 탐색
while (a[start] < pivot) start++;
//end위치의 값이 피벗보다 작은 경우까지 탐색
while (a[end] > pivot) end--;
//만약 start가 end보다 작거나 같으면 두 위치의 숫자 바꾸기
//그리고 그 다음 위치로 각각 이동
if (start <= end) {
change(a, start, end);
start++;
end--;
}
}
return start;
}
//두 위치 간의 숫자 바꾸는 함수
public static void change(int[] a, int n1, int n2) {
int temp = a[n1];
a[n1] = a[n2];
a[n2] = temp;
}
}
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//숫자 가져오기
int n = Integer.parseInt(br.readLine());
//1부터 n번째 줄까지 줄 기준 for문
for (int i = 1; i <= n; i++) {
//줄에 맞춰서 * 작성하는 for문
for (int j = 1; j <= n; j++) {
//오른쪽 정렬을 위해 만약 n-j가 i보다 작을 경우 *, 아니면 띄어쓰기 입력
//System.out.print는 줄 바꿈 안함
if (n-j < i) System.out.print("*"); else System.out.print(" ");
}
//System.out.println은 줄 바꿈
System.out.println("");
}
}
}