프로그래밍(programming)

[백준 문제 10430]_자바 나머지

정보나눔중 2020. 11. 29. 00:58
반응형

단계별로 풀어보기

 

1단계 : 입출력과 사칙연산

-6단계 : (A+B)%C는 ((A%C) + (B%C))%C 와 같을까?

           (A×B)%C는 ((A%C) × (B%C))%C 와 같을까?

           세 수 A, B, C가 주어졌을 때, 위의 네 가지 값을 구하는 프로그램을 작성

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        
        while(A<2 || A>10000 || B<2 || B>10000 || C<2 || C>10000){
            //System.out.println("A,B,C를 2 ~ 10,000 사이의 수로 입력하세요.");
            A = sc.nextInt();
            B = sc.nextInt();
            C = sc.nextInt();
        }
        
        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);
    }
}
cs
반응형