-
[알고리즘-JAVA] 백준 알고리즘 10430번 - 나머지알고리즘 2019. 8. 6. 23:01
접근 과정
1. 어떤 문제로 이해 했는가? 그리고 문제의 제약 조건은?(A+B)%C 는 (A%C + B%C)%C와 같은지,
(A*B)%C는 (A%C * B%C)%C와 같은지를 확인하는 문제이다.
2. 나의 방식대로 문제를 재정의 하자.단순히 두 식이 같은지 확인해주면 된다.
답은 같다.
3. 어떤 알고리즘과 자료구조를 사용할 것인가?X
4. 어떻게 계산할 것인가?
1) 입력BufferedReader, InputStreamReader를 이용
2) 시간 복잡도 계산
단순 계산 과정이므로 O(1)
5. 주의할 점은 무엇인가?.
6. 풀이 과정
3개의 입력을 받고
식대로 그대로 출력해주기만 하면 된다.
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.StringTokenizer; public class Main { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer stk = new StringTokenizer(br.readLine()," "); int a = Integer.parseInt(stk.nextToken()); int b = Integer.parseInt(stk.nextToken()); int c = Integer.parseInt(stk.nextToken()); System.out.println((a+b)%c); System.out.println((a%c + b%c)%c); System.out.println((a*b)%c); System.out.println((a%c * b%c)%c); } }
'알고리즘' 카테고리의 다른 글
[알고리즘-JAVA] 백준 알고리즘 1934번 - 최소공배수 (0) 2019.08.07 [알고리즘-JAVA] 백준 알고리즘 2609번 - 최대공약수와 최소공배수 (0) 2019.08.06 [알고리즘-JAVA] 백준 알고리즘 9465번 - 스티커(미완) (0) 2019.08.06 [알고리즘-JAVA] 백준 알고리즘 11057번 - 오르막수 (0) 2019.08.05 [알고리즘-JAVA] 백준 알고리즘 10844번 - 쉬운 계단 수 (0) 2019.08.04