์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ/BOJ_Java

[BOJ/Step1] 10430 : ๋‚˜๋จธ์ง€ (JAVA)

NaNaRin๐Ÿ™ƒ 2021. 1. 6. 17:44

www.acmicpc.net/problem/10430

 

10430๋ฒˆ: ๋‚˜๋จธ์ง€

์ฒซ์งธ ์ค„์— A, B, C๊ฐ€ ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค. (2 ≤ A, B, C ≤ 10000)

www.acmicpc.net


๋ฌธ์ œ

(A+B)%C๋Š” ((A%C) + (B%C))%C ์™€ ๊ฐ™์„๊นŒ?

(A×B)%C๋Š” ((A%C) × (B%C))%C ์™€ ๊ฐ™์„๊นŒ?

์„ธ ์ˆ˜ A, B, C๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์œ„์˜ ๋„ค ๊ฐ€์ง€ ๊ฐ’์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— A, B, C๊ฐ€ ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค. (2 ≤ A, B, C ≤ 10000)

 

์ถœ๋ ฅ

์ฒซ์งธ ์ค„์— (A+B)%C, ๋‘˜์งธ ์ค„์— ((A%C) + (B%C))%C, ์…‹์งธ ์ค„์— (A×B)%C, ๋„ท์งธ ์ค„์— ((A%C) × (B%C))%C๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

 

์˜ˆ์ œ ์ž…๋ ฅ 1

5 8 4

 

์˜ˆ์ œ ์ถœ๋ ฅ 1

1

1

0

0


ํ’€์ด

 

import java.util.Scanner;

public class B10430 {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int 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 );
		
	}

}