Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Solve] BJ1978 - 소수 찾기 #12

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion algorithm/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions algorithm/src/BJ1009.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import java.util.Scanner;

public class BJ1009 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt(); //반복 횟수
int a, b, c;

for(int i = 0; i < t; i++) {
a = in.nextInt();
b = in.nextInt();
c = 1;

for(int j = 0; j < b; j++){
c = (c * a) % 10;
if (c == 0)
c = 10;
}
System.out.println(c);
}
}
}
27 changes: 27 additions & 0 deletions algorithm/src/BJ1212.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.util.Scanner;

public class BJ1212 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String a = in.nextLine();
StringBuilder b = new StringBuilder();
//객체를 생성하는 것이 아니라 기존의 데이터에 더하는 방식을 사용하여 속도가 빠르다고 한다.
for (int i = 0; i < a.length(); i++){ //입력된 값의 크기만큼 반복
char c = a.charAt(i); //a의 i번째 글자에 차례에 순서대로 갑니다.
switch (c) { // b.append(3 "011", 1 "001", 4 "100") 더해줌
case '0': b.append("000"); break;
case '1': b.append("001"); break;
case '2': b.append("010"); break;
case '3': b.append("011"); break;
case '4': b.append("100"); break;
case '5': b.append("101"); break;
case '6': b.append("110"); break;
case '7': b.append("111"); break;
default: break;
}
}
if (b.charAt(0)=='0') b.deleteCharAt(0);
if (b.charAt(0)=='0') b.deleteCharAt(0);
System.out.println(b);
}
}
29 changes: 29 additions & 0 deletions algorithm/src/BJ1373.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import java.util.Scanner;
public class BJ1373 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String a = in.nextLine();
int size = a.length();
if(size%3==1)
a = "00" + a;
if(size%3==2)
a = "0" + a;

StringBuilder b = new StringBuilder();

int q = 0;
int w = 0;
int e;

for (int i = 0; i <= a.length()-1; i++){
int num = a.charAt(i)-'0';
if(i%3==0) q = num*4;
else if(i%3==1) w = num*2;
else {
e = num;
b.append(q+w+e);
}
}
System.out.println(b);
}
}
18 changes: 18 additions & 0 deletions algorithm/src/BJ1789.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.util.Scanner;

public class BJ1789 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long a = in.nextLong();
//자바 int는 21억정도까지 밖에 안됨
//그러나 문제는 42억까지 요구함
long sum = 0;
int count = 0;
for(int i = 1; ; i++) {
if(sum > a) break;
count++;
sum += i;
}
System.out.println(count-1);
}
}
21 changes: 21 additions & 0 deletions algorithm/src/BJ1934.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.util.Scanner;

public class BJ1934 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
int d = 0;
for (int i = 0; i < t; i++) {
int a = in.nextInt();
int b = in.nextInt();
d = a * b;
int c;
while (b != 0) {
c = a % b;
a = b;
b = c;
}
System.out.println(d/a);
}
}
}
21 changes: 21 additions & 0 deletions algorithm/src/BJ1978.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.util.Scanner;
public class BJ1978 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int[] a = new int[N];
int sum = 0;
for (int i = 0; i < a.length; i++) {
a[i] = in.nextInt();
for(int j = 2; j <= a[i]; j++) {
if(j == a[i]){
sum++;
}
if (a[i] % j == 0) {
break;
}
}
}
System.out.println(sum);
}
}
20 changes: 20 additions & 0 deletions algorithm/src/BJ2839.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import java.util.Scanner;

public class BJ2839 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int sum = 0;
while(true) {
if(N % 5 == 0) {
System.out.println(N / 5 + sum);
break;
} else if (N < 0){
System.out.println(-1);
break;
}
N = N - 3;
sum++;
}
}
}
18 changes: 18 additions & 0 deletions algorithm/src/BJ2921.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.util.Scanner;
public class BJ2921 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int a = 3;
int b = 6;
int m = 0;
int sum = 0;
for (int i = 0; i < N; i++) {
m = a;
sum += m;
a += b;
b += 3;
}
System.out.println(sum);
}
}